I am trying to learn backbone marionette js and developing a small application using this framework.
As part of the application, i am displaying list of users in composite collection view with mode contains name as only attribute. Now i want to add a search button. When user enters string in search box, i want to filter names dynamically on keyup. If he clears the text, i should reset.
I tried to looking at event trigger and listening. But not able to exactly code in my case.
Can someone direct me how to listen to the events. SearchBox is outside this template. Is it possible to listen to events from outside view and do actions like filtering.
Below are my backbone model and collection view :
AttachmentModel = Backbone.Model.extend({
defaults: {
name : "DefaultName"
}
});
//collection definition
AttachmentCollectionModel = Backbone.Collection.extend({
model : AttachmentModel
});
//View definition
AttachmentView = Backbone.Marionette.ItemView.extend({
template : "#attachment-item-template",
tagName : 'li'
});
//Collection view definition
AttachmentCollectionView = Backbone.Marionette.CompositeView.extend({
tagName : "ul",
className : "list",
template : "#attachment-collection-template",
itemView : AttachmentView
});
//Adding region
MyApp.addRegions({
attachmentsDisplayContainer : "#attachmentsDisplayContainer"
});
//Adding initializer
MyApp.addInitializer(function(options){
var attachmentCollectionView = new AttachmentCollectionView({
collection : options.attachmentCollectionModels
});
MyApp.attachmentsDisplayContainer.show(attachmentCollectionView);
});