Created
June 18, 2012 16:35
-
-
Save juanghurtado/2949288 to your computer and use it in GitHub Desktop.
Backbone.Marionette ItemView triggers
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Model | |
module.SampleModel = Backbone.Model.extend({}); | |
// View | |
module.SampleView = Backbone.Marionette.ItemView.extend({ | |
template : template_string, | |
// This trigger runs only the first time. After that, "click" event is not triggered (defaults to href="#") | |
triggers : { | |
'click .reload' : 'reload' | |
}, | |
initialize : function() { | |
this.bindTo(this.model, "change", this.modelChanged); | |
this.model.fetch(); | |
}, | |
modelChanged : function() { | |
// App has a Marionette.Region called "mainRegion" | |
App.mainRegion.show(this); | |
} | |
}); | |
// Init | |
var model = new module.SampleModel(); | |
var view = new module.SampleView({ | |
model : model | |
}); | |
view.on('reload', function() { | |
console.log('reload event'); | |
model.fetch(); | |
}); |
I thought 'sync' was supposed to work like that... but the success callback would work certainly
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Is this a better approach?