如何使用自动完成更新ng-repeat变量?

时间:2013-09-25 12:32:21

标签: javascript jquery angularjs jquery-ui-autocomplete angularjs-ng-repeat

感谢SOF解决我在angularjs和autocomplete中的最后一期问题。 Angularjs with jquery auto complete not working

现在,我在ng-repeat中遇到了相同类型的问题...

在视图中

<tr data-ng-repeat="item in pagedItems">
                    <td title={{item.name}}>{{item.name}}</td>
                    <td> <input type=text auto-complete ng-model="item.upload_status">
                    Upload status: {{item.upload_status}}</td>
                    <td title={{item.lat}}>{{item.lat}}</td>
                    <td title={{item.lon}}>{{item.lon}}</td>
                </tr>

指令

myapp.directive('autoComplete', function(autoCompleteDataService) {
return {
    restrict: 'A',
    link: function(scope, elem, attr, ctrl) {

        elem.autocomplete({

            source: autoCompleteDataService.getSource(), 

            select: function( event, ui ) {
                scope.$apply(function() { this.item.upload_status = ui.item.value; });
            },

            change: function (event, ui) {
                if (ui.item === null) {
                    scope.$apply(function() { scope.foo = null });
                }
            },
            minLength: 2
        });
    }
};

});

正在给出错误,

TypeError:无法设置未定义的属性“upload_status”

欢迎更新upload_status的任何想法..

1 个答案:

答案 0 :(得分:1)

this.item.upload_status应为scope.item.upload_status