【问题标题】:Jquery autocomplete with AngularJS filter带有AngularJS过滤器的Jquery自动完成
【发布时间】:2015-06-21 05:36:15
【问题描述】:

我无法让 AngularJS 过滤器与 Jquery 自动完成功能一起正常工作。输入时过滤器工作正常,但如果您从自动完成列表中选择项目,则在再次按下键之前不会更新结果。

jQuery 自动完成:

$( "#searchTeam" ).autocomplete({
            source: teamList,
            change: function(event,ui)
            {
                if (ui.item==null)
                {
                    $("#createPeopleForm_team").val('');
                    $("#createPeopleForm_team").focus();
                    angular.element($(this)).triggerHandler('input')
                }
            },
            minLength: 0
        }).focus(function(){
            //Use the below line instead of triggering keydown
            $(this).autocomplete("search");
        });
    });

过滤器的输入如下所示:

<input id="searchTeam" ng-model="query.team"><br/>

【问题讨论】:

  • 是的,我正在使用 AngularJS 的自动完成功能,它工作正常。

标签: jquery angularjs jquery-ui autocomplete


【解决方案1】:
$( "#searchTeam" ).autocomplete({
            source: teamList,
            change: function(event,ui)
            {
                if (ui.item==null)
                {
                    $("#createPeopleForm_team").val('');
                    $("#createPeopleForm_team").focus();
                    angular.element($(this)).triggerHandler('input')
                }
            },
            minLength: 0
        }).focus(function(){
            //Use the below line instead of triggering keydown
            $(this).autocomplete("search");
$scope.$apply();//might be you missing this
        });
    });

您可能需要使用 $scope.$apply 手动更新绑定。试试看

【讨论】:

  • 正如我提到的,我正在使用 Jquery 自动完成功能,我提供的代码部分是 Jquery,所以我 $scope 在那里未定义
  • 好的,在这种情况下,尝试在调用自动​​完成后将 $scope.$apply 放入...然后回复我,无论发生什么
  • $scope.apply 在我放置的任何地方都不起作用,因为它在那里未定义。我相信我应该使用angular.element($(this)).scope().$apply();,但即使我没有收到任何错误,它也不起作用。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2023-03-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多