gpt4 book ai didi

javascript - Backbone Marionette 集合过滤

转载 作者:行者123 更新时间:2023-11-30 12:55:00 25 4
gpt4 key购买 nike

我试图让用户在集合中搜索显示名称和电子邮件。

到目前为止,我的整个复合 View 看起来像下面的代码。这会呈现并记录我的 var 搜索,但我不确定如何使用该集合。在新的 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')
}
})
})

最佳答案

您可以使用 view.children._viewsMarionette CollectionViewCompositeView 获取 View 。

像这样的代码:

_.each(colView.children._views,function(v){
if(!condition){
v.$el.hide();
}
});

您可以在 colView 中隐藏没有条件的 View (在您的情况下,条件可能是 v.model.get('type') == 'todo') .

关于javascript - Backbone Marionette 集合过滤,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19520730/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com