javascriptbackbone.jsviewmarionette

Uncaught TypeError: Cannot read property 'app' of undefined


I have a composite view:

var resultView = Marionette.CompositeView.extend({
        template : ResultPanel,
        itemView : ResultItemView,
        initialize : function() {
            ...
        },
        itemViewOptions : {
            app : this.options.app
        },

I just want to assign this view's app property to itemView's app property. So i can use this view's app from other view. But I'm getting this error: Uncaught TypeError: Cannot read property 'app' of undefined. What am i doing wrong? Is there another way in order to do this?


Solution

  • possiblity #1: this.option is not yet set when your code executes.

    possibility #2: maybe 'this' is not what you expect it to be. assign var that = this; before and use 'that' instead of 'this'.

    or assign var _options = this.options; before extend() and use _options in the extend.