答案 0 :(得分:1)
<select ng-model="yourModel" ng-options="itemOne.tobName for itemOne in itemsForAddrLevelOne"></select>
在js中你应该设置$scope.yourModel = itemsForAddrLevelOne[0];
答案 1 :(得分:1)
我建议使用ngOptions指令生成选择菜单选项:
<select ng-model="model.livingComplexId" ng-options="itemOne.id as itemOne.tobName for itemOne in itemsForAddrLevelOne"></select>
也许您可以另外将ng-model值更改为model
并使用ng-options="itemOne as ..."
(不使用.id
)并添加track by itemOne.id
。
答案 2 :(得分:0)
我是这样做的...从AngularJS控制器发送请求时带有先前创建的对象的标识符:
$http({
url: '/api/get/object',
method: "POST",
data: {"id" : $scope.someId}
}).success(function (data) {
$scope.object = angular.fromJson(data);
}).error(function(errorData) { ... });
路线:
POST /api/get/object SomeController.object
Play控制器中的操作(我在服务器端使用Play Framework 1.3):
@Transactional
public static void object() {
String id = request.params.get("body").split(":")[1];
SomeObject someObject = SomeObject.findById(Long.parseLong(id));
renderJSON(someObject);
}
我将标识符分配给下拉列表。
<div data-ng-init="initComboBoxes()">
<select id="livingComplexSelectId"
class="form-control m-b"
...
然后,从$scope.object
我提取了必要的ID并由他们填充了选择器。
AngularJS控制器的相关部分:
$scope.initComboBoxes = function() {
var livingComplexSelector = document.getElementById('livingComplexSelectId');
livingComplexSelector.value = $scope.object.LivingComplexId; // set id
//Loading of dependent values...
// $timeout(function(){$scope.afterWaitInitComboBoxes()}, 5000);
}