问题描述
我试图在#each帮助程序的上下文中使用Ember.ContainerView的currentView功能,但是当currentView属性更改为另一个视图时,它失败。
I'm trying to use the the currentView feature of an Ember.ContainerView in the context of a #each helper but it fails when currentView property is changed to another view.
我的目标是允许编辑列表项,当用户点击链接时,将常规视图更改为编辑视图。
My aim here is to allow editing an item of a list, by changing the regular view to an edit view when the user click a link.
主模板:
<ul>
{{#each itemController="person"}}
<li>{{view Ember.ContainerView currentViewBinding="cv"}}</li>
{{/each}}
</ul>
用于显示某人的模板名称:
Template 'name' used to display a person :
{{firstName}} {{lastName}} <a {{action edit}}>edit</a>
currentViewBinding属性('cv')的控件和编辑操作的处理。
Controller for the currentViewBinding property ('cv') and handling for the edit action.
App.PersonController = Ember.ObjectController.extend({
cv: Ember.View.extend({
templateName: 'name'
}),
edit: function() {
this.set('cv', Ember.View.extend({
templateName: 'nameEdit'
}));
}
})
'nameEdit'模板对应于需要显示以编辑人物对象的视图。
'nameEdit' template corresponding to the view that needs to be displayed to edit the person object.
{{input type='text' value=firstName}} {{input type='text' value=lastName}}
说:
但是如果我更换具有视图实例的cv属性(通过使用create()而不是extend())作为重新渲染错误是yield。请参阅我的。
But it's worse if I replace the cv property with a view instance (by using create() instead of extend()) as a re-render error is yield. See this question of mine.
这是jsFiddle要玩
Here is the jsFiddle to play with http://jsfiddle.net/fblanvil/tD3Ph/3/
推荐答案
我最终没有使用ContainerView在所有和使用一个简单的if。但是这并不能解释为什么不能在#each帮助器中使用ContainerView。如果有人认为这是Jira值得注意的话,我会做的。
I ended up not using ContainerView at all and using a simple if. But it doesn't explain why it's not possible to use a ContainerView this way in an #each helper. If someone thinks it's worth a Jira, put a comment and I'll do it.
<ul>
{{#each itemController="person"}}
<li>
{{#if editing}}
{{view templateName='nameEdit'}}
{{else}}
{{view templateName='name'}}
{{/if}}
</li>
{{/each}}
</ul>
毕竟简单有效...
App.PersonController = Ember.ObjectController.extend({
editing: false,
edit: function() {
this.set('editing', true);
}
})
这篇关于不能在#each中交换Ember.ContainerView的currentView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!