Search code examples
ember.jsember-router

emberjs arraycontroller


I'm using the latest 4th pre release of ember. In my application I have some sections that are not connected to Router, but I would like to keep all application in one style and use ArrayController and Em.CollectionView for them.

I tried to make something like this:

var controller = Em.ArrayController.create({content: Em.A()});
Em.CollectionView.create({
    controller: controller 
});
controller.pushObject(Em.Object.create({
    title: 'test'
})) 

and then I got an error that "controller" does not have a container property.

Is it possible to use ArrayController without Em.Router?


Solution

  • Yes it is possible. I was not able to reproduce the error you specified, but did have to make a few changes to get things working.

    var controller = Em.ArrayController.create({content: Em.A()});
    controller.pushObject(Em.Object.create({title: 'dr plimpton'}));
    controller.pushObject(Em.Object.create({title: 'raj'}));
    controller.pushObject(Em.Object.create({title: 'howard'}));
    controller.pushObject(Em.Object.create({title: 'leonard'}));
    
    var myView = Ember.CollectionView.create({
      tagName: 'ul',
      content: controller,
      itemViewClass: Ember.View.extend({
        template: Ember.Handlebars.compile("{{view.content.title}}")
      })
    });
    
    myView.appendTo('body');
    

    Working example (based on ember-1.0.0-pre.4) here: http://jsbin.com/eticuw/1/edit