如何将数组赋给变量.我能够返回我想要的文档,但不能专门获取特定字段内的数组中的所有元素.该字段称为"喜欢".
我的查询过滤我想要的文件:
Posts.find({}, {owner: Meteor.user()})
Run Code Online (Sandbox Code Playgroud)
我想从Posts集合中检索名为"likes"的数组字段中的所有元素.('likes'字段中的每个元素都是一个对象ID)
我尝试使用各种运算符,例如'all'字段中的$ all和$ in,并在console.log中进行测试,但我无法获得ID.根据mongo文档,我需要在运算符中指定一个元素,但我不希望这样.我只想要内心的任何东西.
var likers = Posts.find({}, {owner: Meteor.user()}, {likes: {$in: [] }})
Run Code Online (Sandbox Code Playgroud)
基本上,我试图从"喜欢"字段中检索所有元素,以便我可以进行另一个查询来返回结果.
我正在运行流星0.9+
如何将 设置background-color: #ccc为{{colorLike}}助手?此颜色用于列表项。
<template name="viewPost">
Names:
{{#each userNames}}
<li class="name"><a class="{{colourLike}}" href="{pathFor 'viewItem'}" >{{name}}</a></li>
{{/each}}
</template>
Run Code Online (Sandbox Code Playgroud)
我还想{{colorDislike}} 在bacground-colour: #fff. 这样一来,如果某个元素存在于特定字段中,{{colourDislike}}则将覆盖{{colorLike}}. 我正在收集我可以通过“if”语句实现这一目标。
Template.viewPost.helpers({
userNames: function(){
var selectedPostId = Session.get('postId');
var arrayOfLike = Posts.find({_id: selectedPostId}, {fields: {likes: 1}}).fetch();
var sumArray = _.chain(arrayOfLike).pluck('likes').flatten().value();
return Meteor.users.find({_id: {$in: sumArray}});
},
});
Run Code Online (Sandbox Code Playgroud)
所选帖子来自单击帖子标题时创建的另一个模板的会话集。单击后,用户可以看到喜欢该帖子的所有用户名的列表。所以我的目标是让这些名字<li class="name"><a class="{{colourLike}}" href="{pathFor 'viewItem'}" >{{name}}</a></li>具有某种颜色。
当用户单击名称时,他们能够查看“项目”,它是 viewItem 模板上此特定用户配置文件中的一个字段。该模板还显示了一个“不喜欢”该项目的按钮。如果是,则项目的 userId 存储在 Post 文档的“dislike”字段中。
<template name="viewItem">
{{profile.item}}
<div class="dislike">
<button type="button" class="btn …Run Code Online (Sandbox Code Playgroud) 有人可以在我的代码中看到为什么变量oauthToken在服务器上定义但在Meteor.call的结果中返回到客户端时未定义
我打电话在服务器上发起一个帖子请求
解析了正文,并将值存储到变量oauthToken中
这打印在服务器上,但不会在我的'结果'中打印出客户端
这是因为客户端正在运行模拟吗?我们可以在异步函数中执行"返回"吗?
Server.js
Meteor.methods({
getGoodreads: function () {
request.post('http://www.goodreads.com/oauth/request_token', {oauth:{
consumer_key: '89hdg8pEoMzRdg',
consumer_secret: 'dfgdfgHthtdtjtt' }}, function (error, response, body) {
if (!error && response.statusCode == 200) {
var a = querystring.parse(body)
oauthToken = a.oauth_token
console.log(oauthToken); //prints value i need
return oauthToken
}else{
console.log('there is an error ' + error);
}
});
}
});
Run Code Online (Sandbox Code Playgroud)
client.js
Template.profile.events({
'click #goodreads': function (event) {
event.preventDefault();
Meteor.call('getGoodreads', function(error, result) {
if (error) {
console.log('this is an error ');
} else …Run Code Online (Sandbox Code Playgroud) 我有一个表单,用户将其电子邮件地址和密码输入到联接表单中.这创建了帐户,但我现在想进一步开发它.
client.js:
Template.joinForm.events({
'submit .form-join': function(e, t) {
e.preventDefault();
var email = t.find('#email').value,
password = t.find('#password').value,
username = Random.id(),
array = [],
profile = {
nameOfArray: array
};
Accounts.createUser({
email: email,
username: username,
password: password,
profile: profile
}, function(error) {
if (error) {
alert(error);
} else {
Router.go('/');
}
});
}
});
Run Code Online (Sandbox Code Playgroud)
在创建用户帐户之前,您如何:
检查email集合中是否已存在joinForm中的变量 Meteor.users.在服务器上处理这个?
如果email确实存在,那么拒绝用户创建?
我看过新功能,想知道我是否可以使用这个http://docs.meteor.com/#/full/accounts_validatenewuser
Accounts.validateNewUser(function (user) {
// pseudo if statement code
if (email not exist) {
// …Run Code Online (Sandbox Code Playgroud) 辅助sentencesList对象是包含元素的对象数组text.
HTML:
{{#each sentencesList}}
{{text}}
{{/each}}
Run Code Online (Sandbox Code Playgroud)
CLIENT.JS
sentencesList: function() {
return Session.get(SENTENCES)
}
Run Code Online (Sandbox Code Playgroud)
如何反转排序,即最高索引号显示在顶部,索引位置0处的元素位于底部?
如何制作直方图,以便下面的每一行用条形图表示?例如,x轴"2012-10-02"和y轴"126","2012-10-03"和y轴"11352"......等等.
'date'变量是Date矢量.
date steps
1 2012-10-02 126
2 2012-10-03 11352
3 2012-10-04 12116
4 2012-10-05 13294
5 2012-10-06 15420
6 2012-10-07 11015
7 2012-10-09 12811
8 2012-10-10 9900
9 2012-10-11 10304
10 2012-10-12 17382
Run Code Online (Sandbox Code Playgroud)
谢谢