简体   繁体   English

将参数传递给视图,然后传递给Ember.js中的帮助器

[英]Pass params to a view then to helper in Ember.js

I have 2 views that share a view and I am trying to pass variables between them to turn on|off various html segments. 我有2个视图,它们共享一个视图,并且我试图在它们之间传递变量以打开|关闭各种html段。 Is this possible? 这可能吗? When I run console.log the view.showTitle variable = "view.showTitle" not 1 like it should be? 当我运行console.log时, view.showTitle variable = "view.showTitle"不是应该的1? Odd, right? 奇怪吧?

view 1 calls view 2 and passes param: 视图1调用视图2并传递参数:

{{view "components/social" showTitle="1"}}

view 2 tries to pass this param to a helper function: 视图2尝试将此参数传递给辅助函数:

{{#variable-exists view.showTitle}}
  YES
{{else}}
  NO
{{/variable-exists}}

the helper being called: 该助手被称为:

export default function(elem,options) {
  if (Ember.isEmpty(elem)) {
    return options.inverse(this);
  } else {
    return options.fn(this);
  }
}

I am using the ember cli project to build my ember application. 我正在使用ember cli项目来构建我的ember应用程序。

Current setup at the time of this post: 撰写本文时的当前设置:

DEBUG: -------------------------------
DEBUG: Ember      : 1.5.1
DEBUG: Ember Data : 1.0.0-beta.7+canary.b45e23ba
DEBUG: Handlebars : 1.3.0
DEBUG: jQuery     : 2.1.1
DEBUG: -------------------------------

Following these 2 guides a-way-to-let-users-define-custom-made-bound-if-statements and custom bound helpers I was able to adjust my shared views to use this instead of the standard #if statement. 按照这两个指南,可以让用户定义自定义绑定的if语句自定义绑定的帮助器,我能够调整共享视图以使用此视图而不是标准的#if语句。 This should be more secure than just tossing an #if in there. 这不仅比在其中扔一个#if更安全。

<li>
    <a href="{{unbound view.varProductSocialBlog}}">
        {{#if-equal view.showDiv "true"}}<div>{{/if-equal}}<i class="fa fa-rss-square"></i>{{#if-equal view.showDiv "true"}}</div>{{/if-equal}}
        {{#if-equal view.showTitle "true"}}Blog{{/if-equal}}
    </a>
</li>

I am using the ember cli project to build my ember application. 我正在使用ember cli项目来构建我的ember应用程序。

Current setup at the time of this post: 撰写本文时的当前设置:

DEBUG: -------------------------------
DEBUG: Ember      : 1.5.1
DEBUG: Ember Data : 1.0.0-beta.7+canary.b45e23ba
DEBUG: Handlebars : 1.3.0
DEBUG: jQuery     : 2.1.1
DEBUG: -------------------------------

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM