dignoe
dignoe

Reputation: 1033

Add a static element to a CollectionView

Is it possible to have a CollectionView render a <ul> container, with it's items as <li>'s, and insert a static <li> item in at the end? We are iterating over an array of objects that are rendered as links, and would like a "new" link to be inserted at the end of the list.

Upvotes: 1

Views: 237

Answers (1)

Mudassir Ali
Mudassir Ali

Reputation: 8041

MyApp.TheView = Ember.CollectionView.extend({
  content: [1, 2, 3, 4],
  tagName: 'ul',
  itemViewClass: Ember.View.extend({
    tagName: 'li',
    template: Ember.Handlebars.compile("{{view.content}}")
  }),
  didInsertElement: function() {
    this.pushObject(Ember.View.create({
      tagName: 'li',
      template: Em.Handlebars.compile("<button>NEW</button>")
    }));
  }
})

This should help...

Upvotes: 2

Related Questions