我是新來的角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