关于改变视图和将数组放入集合的问题 Meteor [英] Questions Meteor about changing view and putting array in collection
本文介绍了关于改变视图和将数组放入集合的问题 Meteor的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有两个关于 Meteor 框架的问题
I got two question about the Meteor framework
首先,如何将数组放入 Meteor 集合中?我如何才能将价值推入其中?
First of all, how can I put an array inside a Meteor collection? And how can I push values into it?
第二,当我有一个按钮并单击它时,我如何更改当前视图?这是通过隐藏和显示模板吗?
Second of all, when I have a button and I click on it, how can I change the current view? Is this by hiding and showing templates?
谢谢!
推荐答案
使用 $addToSet 将值推入数组:
Use $addToSet to push values into an array:
var coll = new Meteor.Collection;
coll.insert({myArray: []});
coll.update({}, {$addToSet: {myArray: "myNewValue"}});
有很多方法可以改变视图,但一个简单的方法是使用 Session
并检查它是否在您的模板中具有值:
There are many ways to change views, but an easy one is to use Session
and check whether it has a value in your template:
<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);
}
这篇关于关于改变视图和将数组放入集合的问题 Meteor的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文