backbone.js - Marionette Layout: trigger event on child view -
i have layout view, itemview inside it. have event in item view triggers save function. inside save function trigger event layout captures.
so in code below, in onclicksave modelsavesuccess i'd trigger function in parent layout, have tried this.methodinparent() doesnt work
childview
define(["marionette", "underscore", "text!app/templates/client/form.html", "app/models/client"], function(marionette, _, template, model) { "use strict" return backbone.marionette.itemview.extend({ events: { "submit #saveclient": "onclicksave" }, onclicksave: function(ev) { ev.preventdefault() return this.model.save({}, { success: function() { console.log('success - trigger ') }, error: function(request, error) { console.log(error.responsetext) } }) } }) })
a way without introducing heavy coupling use marionette's event aggregator in linked exemple if use backbone.marionette.application.
// in view ... success: function() { app.vent.trigger('myview:modelsaved'); } ... // in layout initialize() ... app.vent.on('myview:modelsaved', function(){ console.log('model saved in itemview'); }); ...
if don't use backbone.marionette.application can create own backbone.wreqr.eventaggregator.
Comments
Post a Comment