我現在已經嘗試了幾個小時這應該是如此容易,但我不明白爲什麼我沒有得到這個工作。我在做這個Angularjs ng-repeat錯誤的是什麼?
虛擬列表僅用於測試它應該工作,它確實如此。但是,當我連接我的服務器端數據源。由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" }];
}
我建議審查問題進一步。嘗試使用JavaScript調試器來檢查函數中各個點的值。例如,我會很好奇在成功回調中知道'jsonResult.data'的值。 – 2013-04-29 15:11:29
究竟是什麼問題? – remigio 2013-04-29 15:15:18