2013-10-18 7 views
0

개체 이름이 Roption이고 작업 추가에서 세 번째 요소를 제거하고 싶습니다.JavaScript 개체에서 요소를 제거하는 방법

이것은 => I가 가 Roption.items 삭제 사용하고 "{ text: "Child", alias: "addsubbelowchild", action:menuAction}"

[0] .items [2]를.

작동하지만 Roption.items [0] .items.length는 삭제 후에도 동일한 카운트 수를 반환합니다.

정말 삭제되었거나 정의되지 않았습니까?

var Roption = { width: 150, items: [ 
       { text: "Add Task", alias: "addtask", type: "group" , width : 130 , items : 
        [ 
         { text: "Sibling", alias: "addsiblingbelow", action : menuAction}, 
         { text: "Child First", alias: "addsubaboveDirect", action: menuAction }, 
         { text: "Child Last", alias: "addsubbelowDirect", action: menuAction }, 
         { text: "Child", alias: "addsubbelowchild", action:menuAction}, 
         { text: "Advanced Add", alias: "advancedadd", type: "group" , width : 120 , items : 
          [ 
           { text: "Sibling", alias: "addsibling", type: "group" , width : 120 ,items : 
            [ 
             { text: "Below", alias: "addsiblingbelow", action: menuAction }, 
             { text: "Above", alias: "addsiblingabove", action: menuAction } 
            ] 
           }, 
           { text: "Child", alias: "addsubtask", type: "group" , width : 120 ,items : 
            [ 
             { text: "First", alias: "addsubabove", action: menuAction }, 
             { text: "Last", alias: "addsubbelow", action: menuAction } 
            ] 
           } 
          ] 
         } 
        ] 
       } 
      ] 
       , onShow: applyrule 
       , onContextMenu: BeforeContextMenu 
       , onClose : AfterContextMenu 
}; 
function menuAction(row) {} 
function BeforeContextMenu(row) {} 
function applyrule(row) {} 
function AfterContextMenu(row) {} 
+1

를 사용하려고하면 splice' 방법 –

+0

@Anton은 True를 반환 ... –

+0

@IgorDymov가 실제로 작동 ...하지만 스플 라이스를 삭제'사용할 수 있습니다 배열 프로토 타입에서 작동합니다 ... 그리고 그 객체 .. 내가 잘못하면 나를 정정하십시오 !! - –

답변

1

당신이 배열 항목을 삭제하려면 .splice(index,howmany)

Roption.items[0].items.splice(2,1); 
+1

실제로 작동하지만 .. 배열 prototype ... 및 그 객체에 splices 작품 ... 내가 틀렸다면 나를 정정하십시오! –

+1

항목은 배열 안에 개체가있는 배열입니다. @RiteshChandora – Anton

관련 문제