[
{"media_path":"2.jpg","type":"1","complete":"1"},
{"media_path":"2.jpg","type":"1","complete":"2"},
{"media_path":"2.jpg","type":"1","complete":"3"}
]
我想要做的是加载"media_path"
"complete":"2"
到目前为止,我有:
$.getJSON('image.json', function(data) {
$('<img/>').attr("src", item.media_path);
);
但不知何故,我需要过滤"complete":"2"
感谢
答案 0 :(得分:3)
只需迭代返回的json
,如果item.complete === "2"
加载图片。
$.getJSON('image.json', function(data) {
$.each(data, function(i, item){
if(item.complete === "2"){
$('<img/>').attr("src", item.media_path);
}
});
);
关于jsfiddle的简单示例。