对集合的操作(排序,限制,搜索等)
||
通常,当我使用jquery来构建一个简单的应用程序来显示数据时,我会根据某些操作简单地更改一些全局变量,然后在准备从服务器中检索数据时,将这些var传递给服务器。
在ribs.js中执行此操作的好方法是什么?我的观点可以处理吗?到目前为止,我有以下观点:
var ListView = Backbone.View.extend({
initialize: function() {
this.render();
},
render: function() {
template = _.template(\"\\
<table>\\
<% _(collection).each(function(model){%>\\
<tr><td><%=model.name%></td><td><%=model.email%></td></tr>\\
<%}); %>\\
</table>\\
\");
var context = {collection: this.collection.toJSON()};
$(this.el).html(template(context));
$(\'#app\').html(this.el);
}
});
基本上在控制器中,我创建一个users
集合,然后使用users.fetch()
,然后将users
集合传递给新的ListView
对象。我知道初始化函数会自动呈现(这是一种不好的做法吗?)我知道ribs.js中有事件,并且我猜想这就是结束的地方。如何处理按某些字段排序或在某些字段中搜索某些文本或选择返回多少结果(即每页10个)等?
没有找到相关结果
已邀请:
2 个回复
艾食魄轻县
镰茧钩
您可以使用Collection.sort() http://documentcloud.github.com/backbone/#Collection-sort 或者您可以使用Underscore方法并手动重置集合 http://documentcloud.github.com/backbone/#Collection-Underscore-Methods http://documentcloud.github.com/backbone/#Collection-reset