Javascript 选择角度以进行多次选择
我在做这把小提琴 这是我的控制器Javascript 选择角度以进行多次选择,javascript,jquery,angularjs,Javascript,Jquery,Angularjs,我在做这把小提琴 这是我的控制器 angular.module('demoApp', []).controller('DemoController', function($scope) { $scope.options = [ { label: 'one', value: 'a' }, { label: 'two', value: 'b' }, { label: 'three', value: 'c' }, { label: 'four', value: '
angular.module('demoApp', []).controller('DemoController', function($scope) {
$scope.options = [
{ label: 'one', value: 'a' },
{ label: 'two', value: 'b' },
{ label: 'three', value: 'c' },
{ label: 'four', value: 'd' }
];
$scope.selected = [{ 'sel': 'a' },{ 'sel': 'b' },{ 'sel': 'c' } ] ;
});
$scope.options
是我的选择dom的选项,$scope.selected
是我的选择dom中的选择项
这是我的index.html
<body ng-app="demoApp">
<div ng-controller="DemoController">
<div ng-repeat="data in selected">
<select ng-model="data.sel"
ng-options="opt as opt.label for opt in options">
</select>
selected must be : {{data.sel}}
</div>
</div>
</body>
所选内容必须为:{data.sel}
我所拥有的是这个
我需要的是,在第一次加载时,必须像这样选择所选对象
有人能帮我吗?您可以使用
ng init
按$index
选择ng model
值:
<select ng-model="data.sel" ng-options="opt as opt.label for opt in options" ng-init="data.sel = options[$index]"></select>
更新了您的。您可以使用ngInit作为默认设置:
<body ng-app="demoApp">
<div ng-controller="DemoController">
<div ng-repeat="data in selected">
<select ng-model="data.sel"
ng-options="opt.value as opt.label for opt in options" ng-init="data.sel = data.sel || options[$index].value">
</select>
selected must be : {{data.sel}}
</div>
</div>
</body>
所选内容必须为:{data.sel}
hi我试图将所选对象更改为$scope.selected=[{'sel':'a'},{'sel':'a'},{'sel':'a'},{'sel':'a'}];它似乎不起作用。你能试试这个小提琴吗?我不明白你想做什么。$scope.selected必须是select dom的selected值。由于ng selected侦听索引,但$scope.selected返回值not index.hi,我尝试将所选对象更改为$scope.selected=[{'sel':'a'},{'sel':'a'},{'sel':'a'}];它似乎不起作用。你能试试这把小提琴吗?你在评论中试过上面的答案吗?答案中原来的小提琴也被更新了