gpt4 book ai didi

javascript - 嵌套在ng-repeat中的拼接数组,

转载 作者:行者123 更新时间:2023-12-01 15:08:27 25 4
gpt4 key购买 nike

数组的结构是这样的

  $scope.structure = {
sections: [{
id:0,
sectionItems: []
},{
id:1,
sectionItems: []
},{
id:2,
sectionItems: []
}]
};

我有一个嵌套的 ng-repeat,所以我可以在 sectionItems[] 中显示项目(里面应该是对象,其中一个键是名称 - 不相关)

<div ng-repeat="sections in structure.sections" class="col-md-12">
<div class="panel panel-info">
<ul class="screenW-section">
<li class="col-xs-6" ng-repeat="item in sections.sectionItems"
ng-click="item.splice($index, 1)">
{{item.Name}}
</li>
</ul>
</div> </div>

我希望能够在点击时删除项目,但是ng-click="item.splice($index, 1)无论我如何格式化都无法正常工作。

最佳答案

试试这个:

var app = angular.module("testApp", []);
app.controller('testCtrl', function($scope){
$scope.structure = {
sections: [{
id:0,
sectionItems: ['1','2','3']
},{
id:1,
sectionItems: ['11','21','32']
},{
id:2,
sectionItems: ['12','22','32']
}]
};


$scope.remove = function(sectionItems,index){
sectionItems.splice(index, 1);
}
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="testApp" ng-controller="testCtrl">

<div ng-repeat="sections in structure.sections" class="col-md-12">
<div class="panel panel-info">
<ul class="screenW-section">
<li class="col-xs-6" ng-repeat="item in sections.sectionItems"
ng-click="remove(sections.sectionItems,$index)">
{{item}}
</li>
</ul>
</div> </div>

</div>

关于javascript - 嵌套在ng-repeat中的拼接数组,,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36868662/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com