当从render helper设置时,Handlebars模板不符合视图成员 [英] Handlebars template not respecting view member when set from render helper

查看:109
本文介绍了当从render helper设置时,Handlebars模板不符合视图成员的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个表单可以自己填写或嵌入另一个表单,作为一个较大的对象的一部分。当 {{render}} 来自包含句柄模板的表单时,子模板不会遵守视图中的observable。

I have a form that can filled out on its own or embedded into another form, as part of a larger object. When I {{render}} the form from the containing handlebars template, the child template does not respect the observable on the view.

父模板:

{{render "EditIntro" introModule embedded=true}}

其中introModule是容器模型上的一个属性,该模型返回了介绍的特定子模型,该子模型是父类的一部分。

Where introModule is a property on the containers model which returns a the specific submodel for the intro, which is a part of the parent.

子视图:

App.EditIntroView = Ember.View.extend({
  embedded: false,
  isEmbedded: function() {
    return !!this.get('embedded');
  }.property('embedded'),

  templateName: 'intros/edit_intro',
  // etc.

子模板(相关部分):

{{! If this form is embedded, user must use the save button for the parent }}
  {{#unless isEmbedded}}
  <button type="submit" class="btn btn-success">
    <span class="glyphicon glyphicon-save"></span>&nbsp;Save
  </button>
  {{/unless}}

我可以看到Ember Inspector Chrome插件中的属性,它被显示为布尔值 true 。我可以在 isEmbedded 函数上设置一个断点,看到当子模板呈现时不会被调用,但是当我破解了Ember Inspector或者我使用检查器手动更改值。最后,如果我将 EditIntroView 中的默认值设置为 embedded:true ,那么按钮就像我所期望的那样被隐藏。

I can see the property in the Ember Inspector Chrome plugin, where it is shown to be boolean true. I can set a breakpoint on the isEmbedded function and see that it does not get called when the child template renders, but it does get called when I crack open the Ember Inspector or when I use the Inspector to change the value manually. Finally, if I set the default in the EditIntroView to embedded: true, then the button is hidden like I expect.

那么如何让孩子的视图尊重从另一个模板的 {{render}} call?

So how can I get the child view to respect a simple parameter that has been set from another template's {{render}} call?

推荐答案

模板显然没有只在视图中定义的属性,作为其上下文的一部分。由于 isEmbedded 属性仅在视图上而不是模型或控制器,则需要以视图开头。 。所以工作代码修复是简单的:

The template apparently doesn't have properties which are only defined on the view as part of its context. Since the isEmbedded property is only on the view and not the model or controller, it needs to be prefaced with view.. So the working code fix is as simple as:

{{#unless view.isEmbedded}}

就是这样。

关于课堂视图的Ember问题vs实例视图

这篇关于当从render helper设置时,Handlebars模板不符合视图成员的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆