如果selectedOwners
长度为>
0
我希望在页面初始加载时将selectedOwnerDisplay
falg设置为true,则将其设置为false。 addOwner
deleteOwner
长度为selectedOwners
<
时,0
<div class="col-md-12">
<div kendo-grid="selectedOwner" ng-show="selectedOwnerDisplay" k-options="selectedOwnerGridOptions" k-rebind="selectedOwnerGrid"></div>
</div>
不隐藏网格。
知道下面代码有什么问题吗?
有没有更好的方法来实现这些条件?
main.html中
var selectedOwners = [];
$scope.selectedOwnerDisplay = false;
$scope.deleteOwner = function(dataItem) {
angular.forEach(selectedOwners, function(owner, $index) {
if (owner.workerKey === dataItem.workerKey) {
selectedOwners.splice($index, 1);
}
});
if(selectedOwners.length < 0){
$scope.selectedOwnerDisplay = false;
}
}
$scope.addOwner = function(dataItem){
if(selectedOwners.length > 0){
$scope.selectedOwnerDisplay = true;
}
};
ctrl.js
ar -x libfoo.a # unpack libfoo.a
ld -r -o tmp.o *.o # link all objects into tmp.o
nm -u tmp.o # find undefined symbols in tmp.o
rm *.o # remove tmp.o as well as the contents of libfoo.a
答案 0 :(得分:1)
数组长度不能小于零,您可能需要这样:
if (selectedOwners.length === 0) { // or selectedOwners.length < 1
$scope.selectedOwnerDisplay = true;
}
答案 1 :(得分:1)
你以错误的方式吃掉你的角色:)
您不应该尝试检查selectedOwnerDisplay,只需使用
ng-show="selectedOwners.length"
当然,在范围内设置selectedOwners。