[英]How to remove an element from JavaScript Object
我有對象名稱Roption
,我想刪除“添加任務”中的第三個元素。
這個=> "{ text: "Child", alias: "addsubbelowchild", action:menuAction}"
我正在使用Delete Roption.items [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) {}
嘗試使用.splice(index,howmany)
Roption.items[0].items.splice(2,1);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.