Wilker Lucio
Wilker Lucio

Reputation: 2749

rendering views dynamically on EmberJS

I just having a little trouble to implement a special kind of view for Ember, I'm digging on the source for days but can't find how to make it work... Can you take a look and tell me what's wrong? It's a small code, a specific problem when rendering one view from another (it's not doing the binds right...).

The sample code (with comments) that demonstrate the problem is here: http://jsfiddle.net/wilkerlucio/rUUuN/

Edit:

Just to clarify, I'm trying to do a view that dynamically render another view. It can be useful for a lot of implementations, like tabs for example. On tabs you have the tabs and the container that shows current tab, so, the view that I'm trying to accomplish is like this current tab container. Each tab has it own view, and I need that my view be able to render the view for the current tab.

I know I can do things like just hide a view and show the other, but it's not the way I want it right now. This CardView that I'm creating should have a binding to a property that will return a view instance, and the CardView will render this view, and will update if the property that points the view updates.

You can see a more full covered example about what I'm trying to do here: http://jsfiddle.net/wilkerlucio/Ztdpb/

Thanks

Upvotes: 3

Views: 4447

Answers (1)

Veebs
Veebs

Reputation: 2388

I think that you need to specify the template as such:

App.CardView = Ember.View.extend({
    defaultTemplate: SC.Handlebars.compile('{{App.obj.value}}')
});

or

App.CardView = Ember.View.extend({
    templateName: 'sample'
});

If you are planning to have many child views, then you may want to try to use a collection view.

This link is a bit old, but it is still not bad: http://guides.sproutcore20.com/using_handlebars.html

I've also blogged about how it implemented CRUD operations with Ember (SC2) here.

Hope this helps.

Upvotes: 6

Related Questions