2012-12-08 74 views
2

夥計們可以幫助我。 這裏是我有什麼, Ember binding with only an hashemberjs綁定與散列

這裏是模板,

<script type="text/x-handlebars"> 
{{#each Page.PageController.content.tasks}} 
{{#view Page.PageView contentBinding="this"}} 

{{#unless editing}} 
<div> 
    <h2>{{title}}</h2> {{view Ember.Checkbox checkedBinding="editing"}} 
</div> 
{{/unless}} 

{{#if editing}} 
<div> 
    <h2>{{view Ember.TextField valueBinding="title"}}</h2> 
    {{view Ember.Checkbox checkedBinding="editing"}} 
</div> 
{{/if}} 

{{/view}} 
{{/each}}  
</script>​ 

這裏是JS,

Page = Ember.Application.create(); 
Page.PageController = Ember.ObjectController.create({ 
    content: { 
     tasks: [ 
      { 
      title: 'Heading', 
      editing: false}, 
     { 
      title: 'Heading', 
      editing: false} 
     ] 
    } 
}); 

Page.PageView = Ember.View.extend({ 
    edit: function() { 
     var content = this.getPath('content'); 
     content.set("editing", true); 
    } 
});​ 

的問題是,我可以綁定一個普通的布爾舊的散列與視圖Ember.Checkbox,但我怎麼能做到這一點的鏈接操作?

+0

對不起,能否請您解釋一下你正在努力實現/什麼不工作,你有什麼? –

回答

2

您需要使用Ember Objects不是純哈希爲綁定在你需要改變你的代碼如下

Page.PageController = Ember.ObjectController.create({ 
content: Ember.Object.create({ 
    tasks: [ 
     Ember.Object.create({ 
     title: 'Heading', 
     editing: false 
     }), 
     Ember.Object.create({ 
     title: 'Heading', 
     editing: false 
     }) 
    ] 
    }) 
}); 

讓我知道,如果這有助於在上面的例子中正常工作...

更新
Fiddle

+0

感謝您的回覆。我知道我們可以用燼對象來做。在角度上,我們可以使用純哈希。我希望如果我們能夠在燼中做到這一點。另一件事是你看到複選框綁定正在工作,所以我認爲可能有一種方法來使用鏈接。 – Jitu

+0

你能解釋一下你的鏈接是什麼意思嗎? –

+0

這是另一個[小提琴](http://jsfiddle.net/ashraf_zmn/DZynj/11/)。點擊時,我想要一個編輯鏈接和內聯編輯。 – Jitu