簡體   English   中英

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

[英]Specify template to be display in a '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',
});

那就是我所擁有的但無法正常工作,是否有可能使我正在嘗試的東西? 其他一些想法?

謝謝!

我不認為templateName: validateSomething() ? 'template1' : 'template2' templateName: validateSomething() ? 'template1' : 'template2'將起作用。 為什么不使用Handlebars {{#if}}{{/if}}助手來確定要渲染的內容(在內容模板中)?

更新:這可能是您追求的更多:

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

我尚未能夠對此進行測試,但足以證明這個想法。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM