我有一個JSON對象陣列陣列減去從JSON對象的JavaScript
posturlContent = [
{ "Title": "Bbc news live", "Content": "<div>this is a test BBC </div>", "Uri": "http://bbc.co.uk" },
{ "Title": "CNN news live", "Content": "<div>this is a test CNN</div>", "Uri": "http://cnn.com" },
{ "Title": "Youtube news live", "Content": "<div>this is a test Youtube </div>", "Uri": "http://youtube.com" },
];
我有一個JS陣列
uris =["http://cnn.com", "http://abcnews.com",...]
我只需要的是URI中,因此下面項posturlContent的輸出。
posturlContent = [
{ "Title": "CNN news live", "Content": "<div>this is a test CNN</div>", "Uri": "http://cnn.com" }
];
我試圖用這個,但取回空posturlContent
$.each(uris, function(){
var siteUrl = this.valueOf();
posturlContent = $.grep(posturlContent, function(item){
return item.Uri.toLowerCase() != siteUrl.toLowerCase();
});
})
從你的'posturlContent'對象中刪除最後一個逗號(最後一個括號後)。 – SimonDever 2013-04-24 03:55:35