gpt4 book ai didi

javascript - 使用 angularjs 想要存储已检查的 Assets

转载 作者:行者123 更新时间:2023-12-03 07:04:27 25 4
gpt4 key购买 nike

 <div style="z-index: 1; position: absolute"ng-show="ctrl.company.selected">
<div style="" ng-repeat="Asset in ctrl.company.selected.Assets">
<div class="pd-5"style="width: 300px; background-color: white; border-bottom: gray solid">
<label>
<input type="checkbox" ng-model="check"/>
{{Asset}}
</label>
</div>
<div ng-show="check">{{Asset}}</div>
</div>
</div>

上面的代码是在检查时显示 Assets ,现在我想存储已检查的 Assets 数组

最佳答案

试试这个,这里可以工作 fiddle

<div style="z-index: 1; position: absolute">
<div style="" ng-repeat="(index,val) in Assets">
<div class="pd-5"style="width: 300px; background-color: white; border-bottom: gray solid">
<label>
<input type="checkbox" name="check[]" ng-click="addToSelectedOrNot(index,flag,val)" ng-true-value="true" ng-false-value="false" ng-model="flag"/>
{{val}}
</label>
</div>
</div>
<div ng-show="selectedAssets.length>0">
<div>----------------Selected------------------</div>
<div>{{selectedAssets}}</div>
</div>

Controller

var myApp = angular.module('myApp',[]);

function MyCtrl($scope) {
$scope.Assets = ['asset1','asset2','asset3'];
$scope.selectedAssets = [];

$scope.addToSelectedOrNot = function(index,flag,val){
if(flag == "true"){
$scope.selectedAssets.push($scope.Assets[index]);
}else if(flag == "false"){
angular.forEach($scope.selectedAssets, function(selVal,selKey )
{
if(val == selVal){
$scope.selectedAssets.splice(selKey,1);
}
});
}
}
}

关于javascript - 使用 angularjs 想要存储已检查的 Assets ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36888357/

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