Kgn*_*web 12 arrays asp.net-mvc-4 angularjs angular-routing angularjs-filter
我的ng-view中有一个10(或n)复选框.现在我想问一下,检查复选框是否复选以及选中复选框的值是最有效或最简单的方法.
<ul>
<li ng-repeat="album in albums">
<input type="checkbox" ng-model="folder.Selected" value={{album.name}} />
</li>
</ul>Run Code Online (Sandbox Code Playgroud)
我有ng-controller(getAlbumsCtrl),因为我有一个数组,我想将所有的checkedbox专辑名称推送到albumNameArray
Icy*_*ool 21
您可以遍历数组以找出所选的数据并推入名称数组.
<ul>
<li ng-repeat="album in albums">
<input type="checkbox" ng-model="album.selected" value={{album.name}} />
</li>
</ul>
$scope.save = function(){
$scope.albumNameArray = [];
angular.forEach($scope.albums, function(album){
if (!!album.selected) $scope.albumNameArray.push(album.name);
})
}
// alternatively you can use Array.prototype.filter on newer browsers (IE 9+)
$scope.save = function(){
$scope.albumNameArray = $scope.albums.filter(function(album){
return album.selected;
});
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
75096 次 |
| 最近记录: |