你最好用“Angular 方式”来做这件事。不需要 JQuery!事实上,如果您发现自己以“JQuery 方式”做事,那么您可能做错了。Mark Rajcok 不久前在 StackOverflow 上对同样的事情提出了一个非常好的问题(和答案):
应用程序.js
//declare your application module.
var app = angular.module('myApp', []);
//declare a controller
app.controller('MainCtrl', function($scope, $http) {
//function to update the list
$scope.updateList = function () {
$http.get('/Cont/GetList', function(data) {
$scope.allParameters = data;
});
};
//initial load
$scope.updateList();
});
索引.html
<!DOCTYPE html>
<html ng-app="myApp">
<head>
<script src="angular.js"></script>
<script src="app.js"></script>
</head>
<body>
<div ng-controller="MainCtrl">
<button ng-click="updateList()">Update</button>
<ul>
<li ng-repeat="parameter in allParameters">{{parameter | json}}</li>
</ul>
<!-- EDIT: Because you requested a select.
or if you wanted to do a select list
assuming every object in your array had a "name" property
you wanted to display in the option text, you could do
something like the following:
(NOTE: ng-model is required for ng-options to work)
-->
<select ng-model="selectedValue" ng-options="p as p.name for p in allParameters"></select>
<!-- this is just to display the value you've selected -->
<p>Selected:</p>
<pre>{{selectedValue | json}}</pre>
</div>
</body>
</html>
编辑:IE中的一个常见问题
因此,首先,如果您在 IE 中遇到问题,我建议您按 F12 并查看您在控制台中遇到的错误。
我见过的最常见的问题是破坏 IE 中的内容,这些问题与 IEconsole.log()
中不存在的命令有关。如果是这种情况,您需要创建一个存根,如下所示:
//stub in console.log for IE.
console = console || {};
console.log = console.log || function () {};