【问题标题】:How to update ng-repeat variable using autocomplete?如何使用自动完成更新 ng-repeat 变量?
【发布时间】:2013-09-25 12:32:21
【问题描述】:

感谢 SOF 解决了我在 angularjs 和自动完成方面的最后一个问题。 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 的想法表示赞赏..

【问题讨论】:

  • 尝试scope.item.upload_status 而不是this.item.upload_status
  • Worked CodeHater.. 谢谢..如何研究这个 angularjs.. 很难开始.. 请添加为答案..
  • 您可以通过 angularjs.org 提供的教程来清楚地了解基础知识。

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


【解决方案1】:

this.item.upload_status 应该是scope.item.upload_status

【讨论】:

    猜你喜欢
    • 2014-11-13
    • 1970-01-01
    • 1970-01-01
    • 2013-07-10
    • 1970-01-01
    • 1970-01-01
    • 2015-08-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多