Kendo Autocomplete with server filtering in Angular, how to?

匿名 (未验证) 提交于 2019-12-03 00:44:02

问题:

I followed this example which describes basic working with Kendo Autocomplete in AngularJS.

Problem is that example works only with local defined data.

Could somebody post example how to work with remote JSON data source?

Link is: http://demos.telerik.com/kendo-ui/autocomplete/angular

Thanks for any advice.

回答1:

Just use $http, so something like this:

angular.module("KendoDemos", [ "kendo.directives" ]); function MyCtrl($scope, $http){  $http.get('/remoteDataSource').     success(function(data) {         $scope.countryNames = data;     }); }

If the data is changing as you type, you could use a $watch also:

angular.module("KendoDemos", [ "kendo.directives" ]); function MyCtrl($scope, $http){  $scope.$watch('textboxValue', function(){     $http.get('/remoteDataSource/' + $scope.textboxValue).         success(function(data) {             $scope.countryNames = data;         });     } });


回答2:

in html just use

<input kendo-auto-complete           k-data-text-field="'ProductName'"         k-data-value-field="'ProductID'"         k-data-source="productsDataSource" />

in Js use

angular.module("KendoDemos", [ "kendo.directives" ])   .controller("MyCtrl", function($scope){       $scope.productsDataSource = {         type: "JSON",         serverFiltering: true,         transport: {             read: {                 url: "http://demos.telerik.com/kendo-ui/service/Northwind.svc/Products",             }         }     };     })


易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!