在EmberJS上动态渲染视图 [英] rendering views dynamically on EmberJS

查看:94
本文介绍了在EmberJS上动态渲染视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是有点麻烦来实现一种特殊的视图为Ember,我正在挖几天,但找不到如何使它的工作...你可以看看告诉我什么错误?这是一个小代码,一个特定的问题,当从另一个渲染一个视图(它不是做的绑定...)。

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...).

示例代码(与评论),演示问题出在这里: http://jsfiddle.net/wilkerlucio/rUUuN/

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

编辑:

只是为了澄清,我试图做一个动态渲染另一个视图的视图。它可以用于很多实现,例如选项卡。在选项卡上,您有选项卡和显示当前选项卡的容器,因此,我想要完成的视图就像这个当前选项卡容器。每个标签都有自己的视图,我需要我的视图可以呈现当前选项卡的视图。

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.

我知道我可以做一些事情,就像隐藏视图并显示另一个,但现在不是我想要的方式。我创建的CardView应该具有绑定到将返回视图实例的属性,并且CardView将呈现此视图,并且如果指向视图的属性更新,则将更新。

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.

您可以在这里查看更全面的示例: http: //jsfiddle.net/wilkerlucio/Ztdpb/

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

谢谢

推荐答案

我认为你需要指定这样的模板:

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

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

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.

此链接有点旧,但仍然不错: http://guides.sproutcore20.com/using_handlebars.html

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

我还介绍了如何使用Ember实现CRUD操作(SC2) here

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

希望这有帮助。

这篇关于在EmberJS上动态渲染视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆