我有一個名爲World.json的大文件,其中包含世界各地所有國家的大量數據。我一直在使用一個列表來顯示錶中的所有數據。我想按順序對所有值進行排序。但問題是,我所有的int值都是world.json中的字符串。我知道,我需要使用parseInt函數,使其工作,但 嘗試一切沒有任何成功將字符串錶轉換爲int範圍
只是和示例代碼World.js
"Country": [
{
"Code": "AFG",
"Name": "Afghanistan",
"Continent": "Asia",
"Region": "Southern and Central Asia",
"SurfaceArea": "652090.00",
"IndepYear": "1919",
"Population": "22720000",
"LifeExpectancy": "45.9",
"GNP": "5976.00",
"GNPOld": "NULL",
"LocalName": "Afganistan/Afqanestan",
"GovernmentForm": "Islamic Emirate",
"HeadOfState": "Mohammad Omar",
"Capital": "1",
"Code2": "AF"
},
{
controller.js
countryApp.controller('ctrlMain', function($scope, $http) {
$http.get('world.json').success(function(data){
$scope.world = data;
});
});
countryApp.controller('detailsCtrl', function($scope, $routeParams){
$scope.name = $routeParams.countryName;
});
all.html
<td class="heading"><a href="" ng-click="reverse = predicate == 'LifeExpectancy' && !reverse; predicate = 'LifeExpectancy'">Befolkningsmängd</a></td>
<tr ng-repeat="country in world.Country | filter: { Continent: vDel } | filter:search | orderBy: predicate:reverse">
<td>{{ country.Population }}</td>
</tr>
如果它的選項我會更改JSON文件。如果您的數據是按邏輯鍵入的,則應將其存儲爲鍵入的數據。 –
至少在將數據附加到範圍之前鍵入數據。 –
我寧願不改變json文件,因爲它太龐大了:D –