【发布时间】:2010-02-23 16:45:27
【问题描述】:
我正在尝试通过 ajax 过滤 json 数组,但不知道该怎么做。
{
posts: [{
"image": "images/bbtv.jpg",
"group": "a"
}, {
"image": "images/grow.jpg",
"group": "b"
}, {
"image": "images/tabs.jpg",
"group": "a"
}, {
"image": "images/bia.jpg",
"group": "b"
}]
}
我想要它,以便我只能显示 A 组或 B 组中的项目。
我将如何更改我的 ajax 以过滤内容?
$.ajax({
type: "GET",
url: "category/all.js",
dataType: "json",
cache: false,
contentType: "application/json",
success: function(data) {
$('#folio').html("<ul/>");
$.each(data.posts, function(i,post){
$('#folio ul').append('<li><div class="boxgrid captionfull"><img src="' + post.image + '" /></div></li>');
});
initBinding();
},
error: function(xhr, status, error) {
alert(xhr.status);
}
});
另外,我怎样才能让每个链接都处理过滤器?
<a href="category/all.js">Group A</a> <a href="category/all.js">Group B</a>
抱歉所有这些问题,似乎无法找到解决方案.. 任何正确方向的帮助将不胜感激。
谢谢!
【问题讨论】:
标签: javascript jquery json ajax