[英]My template doesn't recognize a variable. Why does this occur?
My handlebars template has something like this: 我的车把模板具有以下内容:
Template.test.people
<template name="test">
<ul>
{{#each people}}
{{ name }} //name is present in every object in the Template.test.people array.
{{/each}}
</ul>
</template>
The Template.test.people
variable is instantiated ( Template.test.people = [...]
) at some point during runtime when the user clicks on a button. 当用户单击按钮时,在运行时的某个时候实例化
Template.test.people
变量( Template.test.people = [...]
)。 At which time, the above unordered list becomes unhidden. 这时,上面的无序列表将被隐藏。 The list however displays as an empty list!
但是,该列表显示为空列表!
However, even though I can go to the console and read the value of the Template.test.people
variable, at this time, and can clearly see that it has information. 但是,即使此时我可以转到控制台并读取
Template.test.people
变量的值,也可以清楚地看到它具有信息。 The variable is an array of objects. 变量是对象数组。
I tried another workaround just to make sure that things were getting "updated", and I passed my variable through a function like so: 我尝试了另一种变通办法,只是为了确保事情得到“更新”,然后通过这样的函数传递变量:
Template.test.helper = function(){
return Template.test.people;
}
and then change the template to this: 然后将模板更改为此:
<template name="test">
<ul>
{{#each helper}}
{{ name }}
{{/each}}
</ul>
</template>
which also did not work. 这也没有用。
Simply reassigning static template data does not trigger any kind of reactive recalculation. 简单地重新分配静态模板数据不会触发任何形式的反应式重新计算。 Store the objects in
Session
, a collection, or another reactive data source: 将对象存储在
Session
,集合或其他反应性数据源中:
Template.test.people = function() {
return Session.get( "people" );
};
Template.test.events({
"click #the-button": function() {
Session.set( "people", [{ foo: "bar" }, { baz: "qux" }] );
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.