現在,我Posts
模型具有title
和content
場:將用戶字段添加到Meteor記錄?
客戶端/ client.js:
Meteor.subscribe('all-posts');
Template.posts.posts = function() {
return Posts.find({});
};
Template.posts.events({
'click input[type="button"]' : function() {
var title = document.getElementById('title');
var content = document.getElementById('content');
if (title.value === '') {
alert("Title can't be blank");
} else if (title.value.length < 5) {
alert("Title is too short!");
} else {
Posts.insert({
title: title.value,
content: content.value,
author: userId #this show displays the id of the current user
});
title.value = '';
content.value = '';
}
}
});
app.html:
<!--headder and body-->
<div class="span4">
{{#if currentUser}}
<h1>Posts</h1>
<label for="title">Title</label>
<input id="title" type="text" />
<label for="content">Content</label>
<textarea id="content" name="" rows="10" cols="30"></textarea>
<div class="form-actions">
<input type="button" value="Click" class="btn" />
</div>
{{/if}}
</div>
<div class="span6">
{{#each posts}}
<h3>{{title}}</h3>
<p>{{content}}</p>
<p>{{author}}</p>
{{/each}}
</div>
</div>
</div>
</template>
我試着添加一個author
字段(已經做過meteor add accounts-password
和accounts-login
):
author: userId
,但它只是說明誰在 記錄的當前用戶的ID,我想它顯示帖子的作者的電子郵件來代替。
如何做到這一點?