如何过滤然后从json文件加载?
这个问题可能有点令人困惑:) 我有这个 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"}
]
我想做的是加载 "complete":"2"
的 "media_path"
到目前为止我已经:
$.getJSON('image.json', function(data) {
$('<img/>').attr("src", item.media_path);
);
但不知何故我需要过滤 "complete":"2"
谢谢
the question might be a bit confusing :)
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
只需迭代返回的
json
,如果item.complete === "2"
则加载图像。jsfiddle 上的简单示例。
Just iterate over the returned
json
and ifitem.complete === "2"
load the image.Simple example on jsfiddle.