jeudi 13 juillet 2017

how to access model from within a view in emberjs using javascript?

how do i access the model defined in index route model hook from within the container init function i want the container to iterate on the model and create child view for each object in the model array ? here is the code sample

App= Ember.Application.create();
    App.Router.map(function(){

})

App.IndexRoute=Ember.Route.extend({
    model: function(){
        return arr;
    }
})
App.MainView = Em.View.extend({
    classNames: ['mainView']
});

App.MyContainerView = Em.ContainerView.extend({
    tagName:"tbody",
});
var container = App.MyContainerView.create({
    init: function() {
        //this._super();
        //this.pushObject(App.FirstView.create());
        //this.pushObject(App.SecondView.create());
    }
});

App.SingleTaskView = Em.View.extend({
    templateName:'single-task',
    tagName:""
});


App.IndexController= Ember.ArrayController.extend({
    actions: {
        newTask: function(){
            var containerView = Em.View.views['my_container_view']
          var childView = containerView.createChildView(App.SingleTaskView);
            containerView.get('childViews').pushObject(childView);
        }
    }
});




Aucun commentaire:

Enregistrer un commentaire