[英]Javascript - delete object from reference
I have one tree-like structure containing block with certain id. 我有一个包含某些ID的块的树状结构。 Then I have another object, that contains 'id' : objectPart pairs.
然后,我有另一个对象,其中包含“ id”:objectPart对。
Tree: 树:
var tree = [
{
'property' : 'value',
'id' : 'someID',
//more properties...,
'content' : [
{
'prop' : 'something',
...
}
]
},
{
'prop' : 'val',
...
'content' : []
}
]
ID index: ID索引:
{
'someID' : tree[0]
}
I need some way how when I do delete ID_index.someID
, that object gets also deleted from main structure. 我需要一些方法来
delete ID_index.someID
,该对象也会从主结构中删除。
Structure after this code should look like this: 此代码后的结构应如下所示:
[
{
'prop' : 'val',
...
'content' : []
}
]
Instead of using delete
you can write your own remove function. 您可以编写自己的删除功能,而不必使用
delete
。 It should look like this: 它看起来应该像这样:
function myRemove(stringId) {
delete ID_index[stringId]; //remove property from ID_index
objIndex = ... //find object index in tree array
tree.splice(objIndex, 1); //remove object from tree array
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.