xiaolingxiao
xiaolingxiao

Reputation: 4885

Using ember's containerView class, how do I push a named view into the childView array?

The documentation provides an example:

aContainer = Ember.ContainerView.create({
    childViews: ['aView', 'bView', 'cView'],
     aView: Ember.View.create(),
     bView: Ember.View.create(),
     cView: Ember.View.create()
});

This is really neat, however if I want to write a function that adds views when called, how do I name each view that I create? for example:

aContainer = Ember.ContainerView.create({
     childViews: [],

     newView: function( input ){
         var newView = BaseView.create({ field: input });
         this.get('childViews').pushObject( newView );
     }
});

this seem to push an anonymous view into the container. Any thoughts on how to name it?

For example, it'd be neat to have a snippet that says:

newView: function( input ){
    var name = 'view_' + this.get('childViews').get('length') + 1
    var newView = BaseView.create({ field: input, meta: name  })
    this.get('childViews').pushObject( newView );
}

Thank you.

Upvotes: 2

Views: 241

Answers (1)

Bradley Priest
Bradley Priest

Reputation: 7458

I don't think there's a meta attribute to add named views. But you can always just assign them yourself.

 newView: function( input ){
     var name = 'view_' + this.get('childViews.length') + 1
     var newView = BaseView.create({ field: input });
     this.get('childViews').pushObject( newView );
     this.set(name, newView);
 }

Upvotes: 1

Related Questions