如何查看车把模板中的所有可用变量 [英] How to see all available variables in handlebars template
问题描述
我正在开发我的第一个 Ember.js 应用程序,但在连接所有点时遇到了一些问题.如果我能在给定的把手模板中看到所有可用的变量,那将会非常有帮助.
I'm working on my first Ember.js app and am having some trouble connecting all the dots. It would be really helpful if I could just see all the variables available within a given handlebars template.
有一个相关的问题,但你必须知道在使用它的范围内的变量:如何添加控制台.log() Handlebars 模板中的 JavaScript 逻辑?
There is a related question, but you have to know the variable that is in scope to use it: How do I add console.log() JavaScript logic inside of a Handlebars template?
如何输出所有变量?
How can I output all the variables?
推荐答案
一个不错的选择是使用 Handlebars 助手在模板中调试 'this' 的值:1.
a good option is to debug the value of 'this' in a template using the Handlebars helpers: 1.
{{#each}}
{{log this}}
{{/each}}
或者,2. 类似于@watson 建议
or, 2. similar to @watson suggested
{{#each}}
{{debugger}}
{{/each}}
然后在开发工具中深入到this"的本地范围变量
and then drill in to the Local Scope Variables for 'this' in the Dev Tools
或者,3.您可以直接从 Controller init 方法内部记录内容,例如:
or alternatively, 3. you could log things directly from inside your Controller init method, such as:
App.UsersController = Ember.ArrayController.extend({
init: function() {
console.log(this);
console.log(this.getProperties('.'));
}
});
这篇关于如何查看车把模板中的所有可用变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!