我是新来的角js。我有一个链接http://www.bursamalaysia.com/searchbox_data.json,我想获得名称和ID列表。javascript来过滤不需要的数据
我能够从json中的链接获取列表,但我需要在列表中过滤不需要的项目。如果该ID超过4位数,则删除full_name,name,short_name和id。例如:如果id:123456,它需要过滤掉,连同名字,简称。
app.js
abc: {
name: "Momo",
value: "kls",
long: "KLSE",
searchRef: KLSE_SEARCH_REF,
searchRefURL: "http://www.bursamalaysia.com/searchbox_data.json",
},
details.js
$ionicLoading.show();
if ($scope.currentMarket == "abc"){
$webServicesFactory.getNotParsed($marketProvider[$scope.currentMarket].searchRefURL).then(function success(response){
response = JSON.parse(response);
for (var i = 0; i < response[0].length; i++){
$scope.searchRef.push({
name: response[0][i].name || response[0][i].full_name,
symbol: response[0][i].short_name,
code: response[0][i].id,
market: $marketProvider[$scope.currentMarket].long
});
}
console.info($scope.searchRef);
$ionicLoading.hide();
});
}
HTML
<div class="list">
<div class="item" ng-repeat="item in searchItems" ng-click="openDetail(item)">
<p>{{item.symbol}} - {{item.name}}</p>
<p>{{currentMarket | uppercase}}</p>
</div>
</div>
你尝试过什么吗?您可以使用基本的Javascript条件检查轻松完成此操作。 – Hoyen
你可以使用'Array.prototype.filter'和'Array.prototype.map' – Mirodil
@Miro你能详细解释一下吗? – bkcollection