[英]Handlebars Each Helper scope is changes property
嗨,我在應用程序中使用EmberJS,這是我的應用程序模板和應用程序控制器
我在控制器中有一個名為isEditAble的屬性,但是我有一個問題,如果我以前在每個幫助器的外部檢查此屬性,則可以很好地執行。 但是,如果我在每個幫助程序(isEditAble屬性)中使用的范圍不在內部,並且它將始終是錯誤的。
有人可以指導如何在每個助手中使用屬性。
ApplicationTemplate:
//This if executing and textbox is displaying because of isEditAble = true
{{#if isEditAble}}
<div style="width: 40px;">
{{input type=text disabled=isChecked}}
</div>
{{/if}}
{{#each checkBoxes}}
//This if is NOT executing and checkboxes is NOT displaying
//Even Though is EditAble true
{{#if isEditAble}}
<div style="width: 40px;">
{{input type=checkbox disabled=isChecked}}
</div>
{{/if}}
{{/each}}
應用控制器:
App.ApplicationController = Ember.Controller.extend({
appName: 'Tag Editor',
checkBoxes: [
{id: 1, isChecked: true},
{id: 2, isChecked: true},
{id: 3, isChecked: true},
{id: 4, isChecked: true}
],
isEditAble: true
});
您可以使用塊參數來適當設定值的范圍:
{{#each checkBoxes as |cbox|}}
{{#if isEditAble}}
<div>
{{input type="checkbox" checked=cbox.isChecked}} hello
</div>
{{/if}}
{{/each}}
還要注意類型是如何用引號引起來的(而且我認為isChecked
應該切換checked
屬性而不是disabled
)。
編輯:當您使用的是v1.5.1。的較早版本時,塊參數不可用。 您可以使用來訪問父上下文
{{#if ../isEditAble}}
或根上下文(在這種情況下與父上下文相同)
{{#if @root.isEditAble}}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.