V
V
voronin_denis2016-11-25 15:09:26
backbone.js
voronin_denis, 2016-11-25 15:09:26

How to pass model to nested Marionette.CompositeView?

There is a View which is used in CompositeView

var ItemView = Marionette.LayoutView.extend({
        tagName: 'tr',
        template: ItemTemplate,
        regions: {
            footer: "#content"
        },
        
        events: {
            'click td': 'showDismiss'
        },

          showDismiss: function () {
            var EmptyV = new DismissViewComposite();

            if (this.footer.hasView())
                this.footer.empty();
            else {
                <this.footer.show(EmptyV);

            }
            EmptyV.render();
        },

        templateHelpers: function () {
            var model = this.model;
            var numberFunc = this.numberFormatter;
            var dateFunc = this.dateFormatter;
         
            return {
                USER_NAME: model.get('USER_NAME'),
                TMC_TYPE_NAME: model.get('TMC_TYPE_NAME'),
                DISMISS_COUNT: model.get('D<code lang="javascript"></code>ISMISS_COUNT'),
                CULTURE_NAME:  model.get('CULTURE_NAME'),
                DATE: dateFunc(model.get('DATE')),
            };
        },

A region with a similar structure is nested in it, it is displayed on click.
It should also pick up data from the model, but this does not happen. The question is why?
var DismissViewComposite = Marionette.CompositeView.extend({
        childView: new DismissView(),
        childViewContainer: "tbody",
        className: 'historyItem',
        emptyView: EmptyView,
        template: DismissTable,

    });

    var DismissView = Marionette.ItemView.extend({
        tagName: 'tr',
        template: DismissItemTemplate,

        templateHelpers: function () {
            var model = this.model;
            var dismisses = model.get('VIEW_TMC_DISMISS_DATA');
            var numberFunc = this.numberFormatter;
            var dateFunc = this.dateFormatter;

            return {
                CLASS_TYPE: "1",
                COUNT_T:    1,
                ITEM_ID:   1
            };
        },

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Artem Kayun, 2016-11-25
@voronin_denis

You need to explicitly pass the model.
var EmptyV = new DismissViewComposite({
model: this.model
});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question