如何使用angularJS以编程方式将ng-options添加到onsen ui中的选择标签中?
谢谢你,对不起我糟糕的英语。
您应该使用具有 id 和名称的模型列表。例如,
<select ng-model="model_selected.id" ng-options="model.id as model.name for model in list"></select>
补充:下面是一个详细的例子。html是
<div ng-controller="MyCtrl">
<select ng-model="model_selected.id" ng-options="model.id as model.name for model in list"></select>
<div ng-click="change()">Change</div>
</div>
而js是
app.controller('MyCtrl',function($scope) {
$scope.list = [ { "id" : "1" , "name" : "Dog" } , { "id" : "2" , "name" : "Cat" } , { "id" : "3" , "name" : "Bunny"} ];
$scope.change = function() {
$scope.list = [ { "id" : "1" , "name" : "Wolf" } , { "id" : "2" , "name" : "Lion" } , { "id" : "3" , "name" : "Hare" } ];
}
});
最初,您可以从狗、猫和兔子中选择一种。
单击更改锚点后,您可以从狼、狮子和野兔中选择一种。