所以我在這裏幾乎沒有困難。我有一個嵌套的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