我有两个关于 Meteor 框架的问题
首先,如何将数组放入 Meteor 集合中?我怎样才能将值(value)插入其中?
其次,当我有一个按钮并单击它时,如何更改当前 View ?这是通过隐藏和显示模板吗?
谢谢!
最佳答案
使用$addToSet将值插入数组:
var coll = new Meteor.Collection;
coll.insert({myArray: []});
coll.update({}, {$addToSet: {myArray: "myNewValue"}});
有很多方法可以改变 View ,但一个简单的方法是使用 Session
并检查它是否在你的模板中有一个值:
<template name="mytemplate">
<button>Say hello</button>
{{#if sayHello}}<p>Hello</p>{{/if}}
</template>
Template.mytemplate.events({
"click button": function() {
Session.set("sayHello", true);
}
});
Template.mytemplate.sayHello = function() {
return Session.equals("sayHello", true);
}
关于javascript - 关于更改 View 和将数组放入集合中的问题 Meteor,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15278756/