无法在ngSelect中填充模型中的属性

时间:2014-07-03 18:51:19

标签: angularjs select

使用AngularJs创建下拉列表的代码。

<select ng-model="ctrl.editLayout" ng-options="layout.text for layout in ctrl.editLayouts"></select>

JS代码

$scope.ctrl = {"editLayout": "1", "editLayouts": [{ "id": "1", "text": "1 column" }, { "id": "2", "text": "2 column" }]}

当用户选择一个项目时(例如说&#34; 1列&#34;),整个对象将在editLayout中填充,即

editLayout = { "id": "1", "text": "1 column" }

相反,我想要

editLayout = 1

我怎样才能完成它?

1 个答案:

答案 0 :(得分:0)

请改为:

<select ng-model="ctrl.editLayout" ng-options="layout.id as layout.text for layout in ctrl.editLayouts"></select>

关键部分是“layout.id as ...