我有一个名为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 –