Ember.js 访问模板上的应用程序范围对象
我已经定义了一个Ember对象,它只包含一些函数。我想在我的模板中访问这些函数,但不知何故它不起作用。没有给出任何错误,也没有任何日志语句Ember.js 访问模板上的应用程序范围对象,ember.js,handlebars.js,Ember.js,Handlebars.js,我已经定义了一个Ember对象,它只包含一些函数。我想在我的模板中访问这些函数,但不知何故它不起作用。没有给出任何错误,也没有任何日志语句 App.AuthManager = Ember.Object.extend({ isAuthenicated : function () { return true; } }).create(); 现在在我的模板中,我想 {{#if App.AuthManager.isAuthenticated}} <ul&
App.AuthManager = Ember.Object.extend({
isAuthenicated : function () {
return true;
}
}).create();
现在在我的模板中,我想
{{#if App.AuthManager.isAuthenticated}}
<ul>...</ul>
{{/if}}
{{{#if App.AuthManager.isAuthenticated}
…
{{/if}
if语句中的标记总是打印出来的,这里的handlebar不是解释对象函数吗 该指南指出
Each template has an associated controller: this is where the template finds the properties that it displays.
这意味着模板的作用域是控制器,并且只有控制器,您不能直接从Handlebar模板访问应用程序中的其他对象
我认为,您试图实现的目标可以使用的和功能来实现
在控制器中注入AuthManager对象后,您应该能够在模板中访问isAuthenticated属性,如下所示:
{{#if isAuthenticated }}
<ul>....</ul>
{{/if}}
{{#如果已验证}
…
{{/if}
我的答案来源于这个网站:指南上说
Each template has an associated controller: this is where the template finds the properties that it displays.
这意味着模板的作用域是控制器,并且只有控制器,您不能直接从Handlebar模板访问应用程序中的其他对象
我认为,您试图实现的目标可以使用的和功能来实现
在控制器中注入AuthManager对象后,您应该能够在模板中访问isAuthenticated属性,如下所示:
{{#if isAuthenticated }}
<ul>....</ul>
{{/if}}
{{#如果已验证}
…
{{/if}
我的答案来源于以下网站: