2015-03-02 54 views
0

对不起,我的标题很糟糕,我想不出更好的方式来解释我的问题。我在Ghost博客上试图通过过滤掉某些标签的帖子来在我的网站上创建栏目。 Handlebars无法处理我在客户端需要做的事情,所以我在试图完成这个任务的服务器端控制器中进行挖掘。我找到了controllers/frontend.js,并试图修改formatPageResponse函数。使用下划线删除使用嵌入式数组的对象

我试过这样的东西,但它显然不工作。标签是posts数组中每个对象的自己的数组。

posts = _.without(posts, _.findWhere(posts.tags, {'name': 'News'}));

+0

请包括一些样本输入和预期的输出 – thefourtheye 2015-03-02 20:49:22

回答

2

我会假设你posts阵列看起来像这样:

[ { title: "Some Post", tags: { "name": "News" } }, ... ] 

我只想用一个过滤器:

posts = _.filter(posts, function(post){ 
    return !_.any(post.tags, function(tag){ 
     return tag.name === 'News' 
    } 
});