【发布时间】:2015-11-25 12:41:01
【问题描述】:
我正在使用 Backgrid,并在我的控制器中创建 Backgrid 对象,如下所示:
$.when(recipeRequest).done(function (recipes) {
List.grid = new Backgrid.Grid({
columns: columns, // where columns is defined elsewhere
collection: recipes // recipes is the result of a fetch
})
// Then add it to the Marionette template
}
上述工作完美,项目按预期显示
一旦表格显示出来,我们将在服务器端提供过滤功能,如下所示:
filterRecipes: function (query) {
// remove any incomplete network requests
_.each(RecipeManager.fetchXhrs, function (r) {
r.abort()
})
// get a filtered set of recipes
var filteredRecipes = RecipeManager.request('recipe:entities', query)
$.when(filteredRecipes).done(function (recipes) {
// this line shows that the result set is being updated as expected with for example 6 results
console.log(recipes)
// setting the new recipe result set to the grid.collection
List.grid.collection = recipes
// here the table rerenders but there are a LOT more results on the table - not 6 as expected
List.grid.render()
})
}
我希望在返回结果后用新集合重新填充表,但我的表仍然显示所有旧记录。
我正在按照How would I refresh a Backgrid table with new data? 此处编写的示例进行操作,所以一旦集合被重置,它应该重新绘制表格吗?还是我需要先清空桌子?有什么想法我可能会出错吗?
【问题讨论】:
标签: backbone.js marionette backgrid