使用angularjs从远程站点加载选择选项
发布时间:2020-12-17 17:48:29 所属栏目:安全 来源:网络整理
导读:我的 HTML: div id="body" ng-controller="ClientController" select kendo-drop-down-list option data-ng-repeat="client in Clients"{{ client.Name }}/option /select button data-ng-click="loadClients()"Load Clients/button prehttp response data:
我的
HTML:
<div id="body" ng-controller="ClientController"> <select kendo-drop-down-list> <option data-ng-repeat="client in Clients">{{ client.Name }}</option> </select> <button data-ng-click="loadClients()">Load Clients</button> <pre>http response data: {{ data }}</pre> </div> @Scripts.Render("~/bundles/index") 而我的javascript: function ClientController($scope,$http) { $scope.url = "/tracker/api/client"; $scope.selectedClient = null; $scope.Clients = null; $scope.loadClients = function () { $http.get($scope.url).then(function (response) { $scope.data = response.data; $scope.Clients = response.data; }); }; } 当我点击按钮时,我从我的webapi服务器中检索了一堆json-这个数据在响应数据部分显示正常 – 但我的下拉列表总是空的. HTML页面显示: <option value="? object:null ?"></option> 我采取的意味着我没有正确设置数据.我显然是一个有角度的n00b :)我错过了什么? 解决方法
您应该使用ng-options指令.
例: <select ng-model="selectedClient" ng-options="client.name for client in Clients"> 这是更多信息. ng-options的使用对于数组与对象有点不同,并且有几种不同的方法可以使用它,但是对于每个人来说都有一些东西:http://docs.angularjs.org/api/ng.directive:select (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |