javascript - Passing an event to a collection in backbone -
i trying trigger behaviour on collection triggering event elsewhere in app. pretty new backbone, have syntax wrong, seems should work
var test = backbone.model.extend({ }); var tests = backbone.collection.extend({ model: test, events: { "testevent":"testresponce" }, testresponce: function(){ alert('hello world'); } }); var mytest = new test(); mytest.trigger('testevent');
can done? going wrong?
if want call particular method of collection using testevent
event can take path also. working demo
var test = backbone.model.extend({ initialize: function() { this.on('testevent', function() { console.log(this.collection); this.collection.testresponce(); }); } }); var tests = backbone.collection.extend({ model: test, testresponce: function(){ alert('hello world'); } }); var mytest = new test(); var testlist = new tests([mytest]); mytest.trigger('testevent');
Comments
Post a Comment