我现在已经尝试了几个小时,这应该很容易,但我不明白为什么我不能让它工作。
虚拟列表仅用于测试它应该工作并且确实有效。但是,当我连接服务器端数据源时不会。ajax 调用返回的 Json 与虚拟列表中的 Json 相同。
我究竟做错了什么?
这是一个使用 dummylist 的工作示例的链接:http: //plnkr.co/edit/6nBkdBpPVqQ2P8u2BEeY
服务器端是一个 .NET MVC 4 应用程序。
HTML:
<div data-ng-controller="currencyController">
<ul>
<li data-ng-repeat="currency in currencies"><span>{{ currency.CurrencyCode}} - </span><span>{{ currency.CurrencyName }}</span>
</li>
</ul>
</div>
JS:
var currencyTools = angular.module('currencyTools', []);
currencyTools.controller('currencyController',function(currencyService,$scope) {
var path = 'currency/GetCurrencies';
currencyService.getAllCurrencies(path, function (jsonResult) {
$scope.currencies = jsonResult.data;
});
// $scope.currencies = dummyList(); //if i uncomment this it works
})
currencyTools.factory('currencyService', function () {
var service = {
getAllCurrencies: function (path, callback) {
var result = $.ajax({
url: path,
type: 'GET',
dataType: 'json',
data: '',
contentType: 'application/json; charset=utf-8',
success: function(json) { callback(json); }
});
return result;
}
};
return service;
});
function dummyList() {
return [
{ "CurrencyCode": "BAM", "CurrencyName": "Bosnia-Herzegovina Convertible Mark" },
{ "CurrencyCode": "BBD", "CurrencyName": "Barbadian Dollar" },
{ "CurrencyCode": "BDT", "CurrencyName": "Bangladeshi Taka" },
{ "CurrencyCode": "BGN", "CurrencyName": "Bulgarian Lev" },
{ "CurrencyCode": "BHD", "CurrencyName": "Bahraini Dinar" },
{ "CurrencyCode": "BIF", "CurrencyName": "Burundian Franc" },
{ "CurrencyCode": "BMD", "CurrencyName": "Bermudan Dollar" },
{ "CurrencyCode": "BND", "CurrencyName": "Brunei Dollar" },
{ "CurrencyCode": "BOB", "CurrencyName": "Bolivian Boliviano" },
{ "CurrencyCode": "BRL", "CurrencyName": "Brazilian Real" },
{ "CurrencyCode": "BSD", "CurrencyName": "Bahamian Dollar" },
{ "CurrencyCode": "BTC", "CurrencyName": "Bitcoin" }];
}