javascript - Meteor returning method not found error -
drug = new mongo.collection('drugdata'); if(meteor.isclient) { template.drugs.events( { 'submit .new-drug':function(event) { event.preventdefault(); var name = event.target.name.value; var type = event.target.type.value; var rating = number(event.target.rating.value); meteor.call('adddrug',name,type,rating); event.target.name.value=""; event.target.type.value=""; event.target.rating.value=""; } }); template.drugs.helpers( { 'druglist':function() { return drug.find({},{sort:{createdat:-1}}); } } ); } if(meteor.isserver) { meteor.publish('druglist',function() { return drug.find(); }); } meteor.methods( { adddrug:function(name,type,rating) { drug.insert( { name:name, type:type, rating:rating, createdat:new date() }); } } );
//////my router///////
router.configure({ layouttemplate:'layout' }); router.map(function() { this.route('login',{path:'/'}); this.route('claims',{path:'/claims'}); this.route('clients',{path:'/clients'}); this.route('employees',{path:'/employees'}); }); router.route('/drugs', { name:'drugs', template:'drugs', data: function() { meteor.subscribe('druglist'); } });
i'm new meteor , learning routing, having problem displaying data when using routing publish , subscribe. when run code autopublish , insecure , don't use publish , subscribe data shows on pages, when remove autopublish , insecure , use publish , subscribe error 'method "adddrug" not found:404'.
this template code
<template name="drugs"> <h3>this drugs page</h3> <form class= "new-drug"> <input name="name" type="text" placeholder="drug name"> <input name="type" type="text" placeholder="drug classification"> <input name="rating" type="text" placeholder="drug rating"> <button type="submit">add drug<span class="fa fa-plus"></span></button> </form> <div> <ol> {{#each druglist}} <li>{{name}}--{{type}}--{{rating}}</li> {{/each}} </ol> </div> </template>
the data option using in route equivalent of template helper function, , can not used subscribing collection. subscribing done waiton or subscriptions option.
router.route('/drugs', { name:'drugs', template:'drugs', waiton: function() { return meteor.subscribe('druglist'); }, data: function() { return { druglist: drug.find({},{sort:{createdat:-1}}) }; } });
with code wouldn't need helper anymore.
Comments
Post a Comment