简体   繁体   中英

How to use the parentView.template in N nested children in EmberJS

here is what I'm trying to do:

I want to create a tree widget in emberjs that will look like:

    {{view UI.TreeView content="App.rootNode"}}
        {{name}} //-> content of each node, it could be <img src="{{icon}}" /> {{name}}
    {{/view}}

The problem I'm facing is how to use the inner template in my itemViewClass.

Here is what I came up with so far: http://jsfiddle.net/YJ7zM/13/

Relevant line:

   template: Em.Handlebars.compile("{{name}} {{view UI.TreeChildrenView contentBinding=\"children\"}}")

That's the line I don't like and would like to replace with something more like:

   templateBinding: "parentView.template"

The problem is that "parentView" will only work for the first level of the tree, for the other ones it would be "parentView.parentView.template" and so go.

You could always define the template externally and use templateName ...

http://jsfiddle.net/YJ7zM/14/

edit

Revised to address first comment. http://jsfiddle.net/ud3323/mgCva/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM