这是我的简单模板:
<template name="feed">
{{> crewChat}}
{{> statusSubmit}}
{{#each statuses}}
{{> statusItem}}
{{/each}}
</template>
在我的groupChat.html和groupChat.js文件中:
<template name="crewChat">
<div class="post-item">
<div class="ui feed">
{{#each messages}}
{{> crewChatMessage}}
{{/each}}
</div>
</div>
<form class="new-message">
<textarea id="message" name="content" rows="2"></textarea>
<div class="post-actions text-right">
<input type="submit" value="Submit" class="compact tiny ui primary button">
</div>
</form>
</template>
Template.crewChat.events({
'submit form': function(e) {
e.preventDefault();
var crewMessage = {
content: e.target.content.value
}
Meteor.call('createCrewMessage', crewMessage, function(error, result) {
if (error)
return alert(error.reason);
console.log("Create new crew message.");
$(e.target.content).val("");
});
}
});
Template.crewChat.helpers({
messages: function() {
return CrewMessages.find({}, {sort: {submitted: -1}});
}
});
当我提交一条新邮件时,我可以看到它是使用Mongol添加的(并且在视觉上一瞬间),但它会立即删除。
Meteor.methods({
createCrewMessage: function(crewMessageAttributes) {
var user = Meteor.user();
var crewMessage = _.extend(crewMessageAttributes, {
userId: user._id,
author: user.profile.firstName,
submitted: new Date()
});
var crewMessageId = CrewMessages.insert(crewMessage);
return { _id: crewMessageId };
}
});
为什么会发生这种情况的任何想法?
答案 0 :(得分:0)
我忘了订阅我发布的收藏品。
'remove'