javascript - Access Backbone fetch parameters -
i need able pass server info when calling fetch on backbone collection. on front-end have code, passing data:{} fetch function along success , error callbacks. looking @ docs backbone fetch:
http://backbonejs.org/#collection-fetch
perhaps not passing in parameters correctly fetch function? perhaps should in array []...
var lineupcollection = new lineupcollection([]); var loadteamsonpageload = (function() { lineupcollection.url = '/api/lineups'; lineupcollection.fetch( { processdata: true, data: { team_id:$("#team_id").attr("value") } }, { success: function (result) { if(window.teamdashboardtableview === undefined){ window.teamdashboardtableview = new teamdashboardtableview({el: $("#team-dashboard-table-div")}); } window.teamdashboardtableview.render(); }, error: function (err) { settimeout(function () { alert('error fetching lineupcollection - ' + err.message); }, 1); } } ); })();
which load backbone collection table.
it's call method on back-end:
exports.getbackbonelineups = function(req,res,next){ var user_id = req.mainuser._id; console.log('req.params',req.params); //empty {} console.log('req.team',req.team); //undefined console.log('team_id',req.team_id); //undefined console.log('req.data',req.data); //undefined console.log('req.body',req.body); //empty {} var team_id = req.team._id; //undefined exception, can't read property _id of undefined var system_db = req.system_db; var lineup = lineupmodel.getnewlineup(system_db,user_id); lineup.find({team_id:team_id}, function (err, lineups) { if (err) { return next(err); } res.json(lineups); }); };
however, totally failing far how access data supposedly past server client. can't find example , getting tired of guessing. what's best way this?
edit: tried passing {data:{}, success: function(), error: function()}
in same javascript object, didn't work.
fetch
takes 1 argument (see http://backbonejs.org/#collection-fetch). instead, should alter backend specify team id in resource's url. example:
lineupcollection.url = function(){ return '/api/lineups?team_id=' + this.team_id; }; lineupcollection.team_id = $("#team_id").attr("value"); lineupcollection.fetch({ success: ..., error: ...});
Comments
Post a Comment