the question might be a bit confus开发者_StackOverflowing :) i have this json:
[
{"media_path":"2.jpg","type":"1","complete":"1"},
{"media_path":"2.jpg","type":"1","complete":"2"},
{"media_path":"2.jpg","type":"1","complete":"3"}
]
what i want to do is to load the "media_path"
of the "complete":"2"
so far i have:
$.getJSON('image.json', function(data) {
$('<img/>').attr("src", item.media_path);
);
but somehow i need to filter "complete":"2"
thanks
Just iterate over the returned json
and if item.complete === "2"
load the image.
$.getJSON('image.json', function(data) {
$.each(data, function(i, item){
if(item.complete === "2"){
$('<img/>').attr("src", item.media_path);
}
});
);
Simple example on jsfiddle.
精彩评论