0

这是我的 angularjs 指令:

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. 我错过了什么?

4

1 回答 1

1

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

于 2013-11-13T06:33:32.590 回答