仅当有多个选项时,我才会显示“选择”标记。
这是我的选择:
<select ng-model='nodes[$index+1]' ng-options='key as key for (key,value) in simpleTypes[$index]' ng-change="getChildren($index)" ng-repeat="node in nodes">
<option value="">select node</option>
</select>
我试过
ng-show="Object.keys(simpleTypes[$index]).length > 1"
但问题是它计算的是前一个选择的长度而不是当前的长度。
编辑:正如评论中所提到的,我应该能够使用simpleTypes [$ index + 1],但它是由异步的HTTP请求创建的,所以我认为在创建数组之前会评估ng-show。所以我想知道我是否可以做类似
的事情ng-show="ngOptions.length > 1"
编辑:根据要求,我的模型映射:
$scope.simpleTypes=[];
$scope.nodes=[];
相关功能:
$scope.getChildren = function(index){
if(index < $scope.nodes.length - 2 ){
var temp = $scope.nodes[index+1];
$scope.nodes=$scope.nodes.slice(0,index+1);
$scope.nodes[index+1]=temp;
}
var sentType = [];
for(var i = $scope.nodes.length-1; i>0;i--){
sentType.push($scope.nodes[i]);
}
$scope.types = $http({
method: 'GET',
url: 'http://localhost:8080/hello/children',
headers: {'Content-Type': 'application/json', 'standard' : $scope.selectedstandard, 'type' : sentType.reverse().join(":")}
}).success(function (data)
{
$scope.types=data;
var i=0;
var simpleTypesTemp = JSON.parse(JSON.stringify($scope.types));
$scope.simpleTypes[index+1] = JSON.parse(JSON.stringify(simpleTypesTemp));
console.log($scope.simpleTypes[index+1]);
});