********下面是html文件********
中的代码 <div class="form-group">
<label for="" class="col-sm-2 control-label">Count:</label>
<div class="col-sm-10">
<select class="form-control" ng-model="selectedItem"
ng-options="obj.name for obj in listObj">
</select>
</div>
</div>
******code in js******
var listCount = [];
for(var i=1;i<6;i++){
var obj = {
"name":i,
"value":i
};
listCount.push(obj);
};
$scope.listObj = listCount;
**** //响应我的名字和价值在1到6之间****
scope.selectedItem= {"name":response.name,
"value":frac.convert(response.value, false).numerator
};
答案 0 :(得分:0)
您应该使用:
for(var i = 0, len = $scope.listObj.length; i < len; i++) {
if(response.name === $scope.listObj[i].name) {
$scope.selectedItem = $scope.listObj[i];
break;
}
}
如果要选择项目,$ scope.selectedItem应引用$ scope.listObj数组中的该项目。