首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ng-选择的模型集值

ng-选择的模型集值
EN

Stack Overflow用户
提问于 2013-11-13 05:59:00
回答 1查看 302关注 0票数 0

这是我的天使指令:

代码语言:javascript
复制
dicApp.directive('listpanel', function ($resource) {
    return {
        restrict: 'E',
        template: '<select ng-model="selectedDictionary" ng-change="listChange()">' +
            '<option value="">--Select--</option>' +
            '<option ng-repeat="item in items" value="{{item.value}}">{{item.label}}</option> ' +
            '</select>',
        replace: true,
        link: function (scope, elem, attrs) {
            var list = $resource('http://test.com')
            list.get(function (data) {
                scope.items = [];

                for(var index = 0; data.documents[0].Dictionaries.length > index; index++){
                    scope.items.push({'label': data.documents[0].Dictionaries[index].Label.text, 'value': data.documents[0].Dictionaries[index].Glossaries._id});
                }

                scope.selectedDictionary = '51639519ed7f3dd05869c3d9';

                console.log(data.documents[0].Dictionaries[0].Glossaries._id);
                //scope.selectedDictionary = data.documents[0].Dictionaries[0].Glossaries._id;

            });
        }
    }
});

我确信51639519ed7f3dd05869c3d9值存在于绑定的scope.items中,但是selectedDictionary从未在select中被选中。我遗漏了什么?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-11-13 06:33:32

尝试以这种方式创建选项<select ng-model='data' ng-options="item for item in list"> </select>

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/19946441

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档