我试图允许用户在集合中搜索 displayNames 和电子邮件。
到目前为止,我的整个复合视图看起来像下面的代码。这会渲染并记录我的 var 搜索,但我不确定如何使用 collection.where 以及在新的 Backbone.Collection 之后,我是否调用渲染?
define(["marionette", "text!app/templates/bamboo/employees/collection.html", "app/collections/bamboo/employees",
"app/views/bamboo/employees/item", "jquery"],
function(Marionette, Template, Collection, Row, $) {
"use strict"
return Backbone.Marionette.CompositeView.extend({
template: Template,
itemView: Row,
itemViewContainer: "ul",
collectionEvents: {
'sync': 'hideLoading'
},
events: {
'keyup #filter-input': 'initialize'
},
initialize: function () {
var search = $('#filter-input').val()
if (typeof(search) != "undefined") {
console.log(search)
var filtered = //somehow search collection displayName and email by value search
this.collection = new Backbone.Collection(filtered);
} else {
this.showLoading()
this.collection = new Collection()
return this.collection.fetch()
}
},
showLoading: function() {
this.$el.addClass('loading')
},
hideLoading: function() {
this.$el.removeClass('loading')
}
})
})