0

I have the use case where I need to add custom views to a container view using a specific template and controller. Unfortunately this only works if I don't have the "linkTo" helper in my template. As soon as I add this I can't set a custom controller anymore.

<script type="text/x-handlebars" data-template-name="page1link">
    <!-- remove this line and it will work -->{{#linkTo "page1"}}Go to Page 1{{/linkTo}}
    <p>Link template</p>
</script>


App.IndexView = Ember.ContainerView.extend({
    didInsertElement: function(){
        var LinkView = Ember.View.extend({
            templateName: "page1link",
            controller: Ember.Controller.create()
        });
        for(var i = 0; i < 4; i++){
            this.pushObject(LinkView.create());
        }
    }
});

I always get following exception:

Uncaught TypeError: Cannot call method 'lookup' of null

at following part of the ember code: Ember.LinkView

...
router: Ember.computed(function() {
      return this.get('controller').container.lookup('router:main');
Uncaught TypeError: Cannot call method 'lookup' of null
    }),
...

Somehow the container is not set in this case.

I've created a fiddle showing this issue. Is there a better way to implement this with ember?

JSFiddle Example

Thanks for any hints!

ripcurlx
  • 3
  • 2
  • Is "page1" a route? Also, doesn't ember create a controller for you anyways? Since you're specifying a generic controller I suggest you try removing it. – knownasilya Jun 04 '13 at 12:12

1 Answers1

0

Have a look at the ember guides, specifically over here. They have a controller that displays a list of items each item wrapped in its own controller. While it seems you're trying to do this page by page (Not sure why), the principle is, I think, the same.

Let me know if I've missed the mark and I'll give it some more thought.

have a look at this stack overflow post for infinte scroll in a list using ember.

Community
  • 1
  • 1
Gevious
  • 3,063
  • 2
  • 18
  • 40
  • Hi Gevious! Thanks for your reply. I'm aware of this kind of structure and already use it in my application. The reason why I have to add the views dynamically within the view code is that I'm implementing an endless scrolling for elements with different heights. In that case I have to have access to all items that are rendered on the screen and also need to remove and add items if the user starts scrolling. For that I want to render templates with their associated controller and add them into the scrollable view. – ripcurlx Jun 04 '13 at 09:30
  • Ember will automatically update the list as you get more records from your api. You're describing a more traditional approach to paging (from what I understand). – Gevious Jun 04 '13 at 09:50