Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/441.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/ant/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在EmberJS中的N个嵌套子级中使用parentView.template_Javascript_Ember.js - Fatal编程技术网

Javascript 如何在EmberJS中的N个嵌套子级中使用parentView.template

Javascript 如何在EmberJS中的N个嵌套子级中使用parentView.template,javascript,ember.js,Javascript,Ember.js,以下是我想做的: 我想在emberjs中创建一个树状小部件,如下所示: {{view UI.TreeView content="App.rootNode"}} {{name}} //-> content of each node, it could be <img src="{{icon}}" /> {{name}} {{/view}} 这是我不喜欢的一句话,我想换成更像: templateBinding: "parentView.tem

以下是我想做的:

我想在emberjs中创建一个树状小部件,如下所示:

    {{view UI.TreeView content="App.rootNode"}}
        {{name}} //-> content of each node, it could be <img src="{{icon}}" /> {{name}}
    {{/view}}
这是我不喜欢的一句话,我想换成更像:

   templateBinding: "parentView.template"

问题是“parentView”仅适用于树的第一级,而对于其他树,它将是“parentView.parentView.template”,因此可以这样做。

您可以始终在外部定义模板,并使用
templateName

编辑


修改以处理第一条评论

这需要在创建我的树时对模板进行解耦定义。我想避免这样。对不起,我误读了你的问题。看我修改过的答案。除了方便之外,我不明白为什么在这里分离模板的定义是件坏事。。。我很想知道你为什么认为这条路线更好。谢谢你,罗伊。嗯,我认为把它们放在一起更干净、更直观,因为它们是相互关联的。为了保持一致性,我创建的其他小部件也以同样的方式工作。
   templateBinding: "parentView.template"