2015-09-21 64 views
0

我雖然這將是直截了當的。我有一個包含(foreach國家)名稱,imfcode,lat,lon的數據集。我想將代碼傳遞給一個函數,該函數將過濾返回與傳遞給它的代碼相對應的信息的數據集。所以如果我通過512我應該得到有關阿富汗的信息。我在這裏的功能,會有人介意告訴我我在做什麼擰javascript中返回過濾數組

function loadTrade(imfCode) { 
    console.log ("Country code= ",imfCode) 
    var sourceCountry=dataset.filter function(el){ 
    return el.imfcode===imfCode 
    } 
    console.log ("Source country= ",sourceCountry) 
} 

我不斷收到意外的標記,只是不能看到它。非常感謝

+1

缺少括號'dataset.filter(...)' – Hacketo

回答

0

你錯過了括號後dataset.filter

將其更改爲:

function loadTrade(imfCode) { 
    console.log ("Country code= ",imfCode) 
    var sourceCountry=dataset.filter(function(el){ 
    return el.imfcode===imfCode; 
    }); 
    console.log ("Source country= ",sourceCountry); 
} 
+0

說實話,看着這個項目太長時間。花式錯過了。非常感謝 –