简体   繁体   English

指定要在“渲染”中显示的模板

[英]Specify template to be display in a 'render'

Im trying to use,the 'render' in ember.js, what I want to do is specify which template content will be render: 我正在尝试使用ember.js中的“渲染”,我想做的是指定要渲染的模板内容:

<div>
{{render "content"}}
</div>

<script type="text/x-handlebars" data-template-name="template1"> 
 content 1
<script>

<script type="text/x-handlebars" data-template-name="template2"> 
 content 2
<script>


App.ContentView = Ember.View.extend({
  templateName: validateSomething() ? 'template1' : 'template2',
});

That's what I have but is not working, is it possible make what I'm trying? 那就是我所拥有的但无法正常工作,是否有可能使我正在尝试的东西? Some other ideas?? 其他一些想法?

Thanks! 谢谢!

I don't think templateName: validateSomething() ? 'template1' : 'template2' 我不认为templateName: validateSomething() ? 'template1' : 'template2' templateName: validateSomething() ? 'template1' : 'template2' will work. templateName: validateSomething() ? 'template1' : 'template2'将起作用。 Why not use the Handlebars {{#if}}{{/if}} helper to determine what to render (within your content template)? 为什么不使用Handlebars {{#if}}{{/if}}助手来确定要渲染的内容(在内容模板中)?

Update: This could be more what you are after: 更新:这可能是您追求的更多:

<div>
{{render "content"}}
</div>

<script type="text/x-handlebars" data-template-name="content"> 
  {{#if condition}}
     {{view App.Template1View thisBinding="this"}}
  {{else}}
     {{view App.Template1View thisBinding="this"}}
  {{/if}}
<script>

<script type="text/x-handlebars" data-template-name="template1"> 
 content 1
<script>

<script type="text/x-handlebars" data-template-name="template2"> 
 content 2
<script>

I haven't been able to test this yet, but it should be enough to demonstrate the idea. 我尚未能够对此进行测试,但足以证明这个想法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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