javascript - Documents are added and then removed immediately after -
here's simple template:
<template name="feed"> {{> crewchat}} {{> statussubmit}} {{#each statuses}} {{> statusitem}} {{/each}} </template>
in groupchat.html , groupchat.js files:
<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}}); } });
when submit new message, can see added using mongol (and visually split second), it's removed after.
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 }; } });
any ideas why happening?
i had forgotten subscribe published collection.
meteor.subscribe('crewmessages');
Comments
Post a Comment