所以我在这里几乎没有困难。我有一个嵌套的JSON对象,它是NG重复内,可排序使用AngularJS UI Sortable(基于jQuery UI可排序):Angularjs删除JSon对象
$scope.rootItem = {
id: '1',
type: 'course',
title: 'Adobe Photoshop CC for beginners',
items: [{
id: '2',
type: 'label',
title:'label',
items:[{
id: '3',
type: 'module',
title:'Module title',
items: [{
id: '4',
type: 'topic',
title:'Topic title',
items: [{
id: '5',
type: 'content',
title:'Content title'
}, {
id: '6',
type: 'content',
title:'Content title'
}]
}]
},{
id: '7',
type: 'resources',
title:'Resources'
},{
id: '8',
type: 'module',
title:'Module title',
items: [{
id: '9',
type: 'topic',
title:'Topic',
items: [{
id: '10',
type: 'question',
title:'Question title'
}]
}, {
id: '11',
type: 'topic',
title:'Topic title',
items: [{
id: '12',
type: 'content',
title:'Content title'
}]
}]
}]
},{
id: '14',
type: 'assessmentLabel',
title: 'Assessment Label',
items: [{
id: '15',
type: 'assessment',
title: 'Assessment Title',
items: [{
id: '16',
type: 'courseAssessment',
title: 'Course Question Group',
items: []
}]
}]
}]
};
我应该能够做的就是这个对象中删除任何项目,和如果它有任何孩子,他们也需要删除。
所以我通常会认为是通过$ index并使用splice来删除它(如果它是一个数组)。
但似乎没有这种方式工作的对象,我看网上说删除应该改为使用...
在我的按钮,我尝试通过对象本身,如:
data-ng-click="removeItem(ngModelItem)"
并在我的控制器做这样的事情:
// Remove Item from the list
$scope.removeItem = function(item) {
};
有什么建议吗?
你会知道,鉴于无论是父对象或子阵列项目不好吗?需要了解视图的结构 – charlietfl