How to pass Backbone.js model data to Bootbox with Handlebars.js? -


i have marionette view have method create new model bootbox. need able edit model bootbox, how can i pass current model data box? of current code:

module.views.chaptersx = marionette.compositeview.extend({     template: module.templates['documents/create/course/chapter/index'],     childview: module.views.chapteritemx,     childviewcontainer: "#chapterscollection",     events: {         'click .chapters-create': 'create',         //'click #uploadfileschapters': 'startupload'     },      create: function (evt) {         console.log('create');         evt.preventdefault();         var me = this;         var box = bootbox.dialog({             show: false,             title: "nueva seccion",             message: module.templates['documents/create/course/chapter/chaptermodal'],             buttons: {                 success: {                     label: "guardar",                     classname: "btn-success",                     callback: function () {                         var chapterno = $('#cn').val();                         var chaptername = $('#chaptername').val();                          var chapter = new module.models.chapter({                             chapterno: chapterno,                             chaptername: chaptername,                          });                         me.collection.add(chapter);                      }                 }             }         });         box.on("show.bs.modal", function () {             console.log('numbers');             var number = (me.collection.size() + 1);             $('#cn').val(number);         });         box.modal('show');       }, 

tl;dr - use model's custom events or event bus pass data.


  • you can reference this.model in view, of compromise (you're tying view , model).

  • you pass data via event object's data property, you're gonna have extend methods , backbone's nitty gritty.

  • use data- attribute on element:

    <div class="chapters-create" data-cats></div> 
    create: function (evt) {     var cats = $(evt.currenttarget).data('cats');     // ... } 

    … considered bad habit way - you're still tying data dom (or model view, mvc speaking).

well, don't either of above, tend have high coupling - i'd custom events on shared model resides @ higher level.

i don't know data comes from, bottom line - shoot in custom event, or, better yet, use event bus, 1 offered marionette.js.


Comments

Popular posts from this blog

PHP DOM loadHTML() method unusual warning -

python - How to create jsonb index using GIN on SQLAlchemy? -

c# - TransactionScope not rolling back although no complete() is called -