0

I have created nested backbone view like this.

var parentView = Backbone.View.extend({ 
    el: 'body',
    template: Html,
    events: { 'click #seemore': 'seeMore' },
    initialize:function () { this.render(); },
    render:function () {
        this.$el.html(this.template);

        //here I am creating nested view
        this.childView = new ChildView();
    }
    seeMore:function (e) {
        //here I am calling nested view's method/function
        this.childView.getData();
        return false;
    },
})

If I create view like this, Is this bed practice? means my child view is come under parent class scope, Here I just using single method of child class, So, I think why I am giving whole object/class in parent class scope?

3
  • As far as I know, it's not a bad practice. You can initialize child view under a parent view.
    – msapkal
    Apr 7, 2014 at 9:07
  • thanks @MaheshSapkal, I have doubt about variable scope. my child view's all variables comes under parent view scope. Is this utilized more memory? Apr 7, 2014 at 9:10
  • It is not a bad practice. Apr 7, 2014 at 19:06

1 Answer 1

0

Why doesn't the child view contain the see more button and gets the data itself?

1
  • hi @OferHaber, In above situation, my parent view is a collection of child view. so "See more" button should come in parent view. Apr 11, 2014 at 11:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.