将参数传递给视图,然后传递给Ember.js中的帮助器 [英] Pass params to a view then to helper in Ember.js
问题描述
我有2个视图共享一个视图,并且我试图在它们之间传递变量以打开|关闭各种html段。这可能吗?当我运行console.log时, view.showTitle变量= view.showTitle
不是1,应该是这样吗?奇怪,对吧?
I have 2 views that share a view and I am trying to pass variables between them to turn on|off various html segments. Is this possible? When I run console.log the view.showTitle variable = "view.showTitle"
not 1 like it should be? Odd, right?
视图1调用视图2并传递参数:
view 1 calls view 2 and passes param:
{{view "components/social" showTitle="1"}}
视图2试图将此参数传递给辅助函数:
view 2 tries to pass this param to a helper function:
{{#variable-exists view.showTitle}}
YES
{{else}}
NO
{{/variable-exists}}
被称为帮助者的
export default function(elem,options) {
if (Ember.isEmpty(elem)) {
return options.inverse(this);
} else {
return options.fn(this);
}
}
我正在使用 ember cli 项目来构建我的ember应用程序。
I am using the ember cli project to build my ember application.
发布时间:
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: -------------------------------
推荐答案
遵循这两个指南 a-way-to- let-users-define-custom-made-bound-if-statements 和自定义绑定助手我能够调整共享视图以使用此视图而不是标准的#if语句。这不仅比在其中扔#if更安全。
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. This should be more secure than just tossing an #if in there.
<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>
我正在使用 ember cli 项目来构建我的ember应用程序。
I am using the ember cli project to build my ember application.
本文发布时的当前设置:
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: -------------------------------
这篇关于将参数传递给视图,然后传递给Ember.js中的帮助器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!