javascript - FindRecord with Ember and MongoDB -
i have been looking on web answer have not been able find one, maybe not asking right questions here goes.
so im building crud webapp using express, mongodb , ember cli, far can save data mongodb database (/events/new) , display events (events/all) seem stuck when accessing individual event ideal url /events/:eventname...
i know i'm getting right result server, , getting one, in ember console, model shows records, plus cant seem render actual content model screen. if happen go localhost:300/event/xxxx ember console shows 2 records 1 want , sort of dummy 1 having xxxx id , rest of fields undefined... need create new route single record? or there way use same route defined records in events/all ? how data displayed on screen ? why see records when access /events/eventname ? following best practices here ?
express:
app.get('/api/events', function(req,res) { eventsmodel.find({},function(err,docs) { if(err) { res.send({error:err}); } else { // want display current events, // filter throught them , return // current ones var current = []; var today = new date(); var tomorrow = today.setdate(today.getdate() - 1); docs.foreach(function(item){ if(item.date >= tomorrow){ // console.log('new'); current.push(item); } }); res.send({events:current}); console.log('/api/events'); } }); }); app.get('/api/events/:name', function(req, res){ console.log(req.url); console.log('/api/events/event'); eventsmodel.findone({name: req.params.name},function(err,docs) { if(err) { res.send({error:err}); } else{ res.send({event:docs}); } }); });
ember router.js
router.map(function() { this.route('events', function() { this.route('new'); this.route('update'); this.route('all'); this.route('event', { path: ':name' }); }); });
ember events.event routes
export default ember.route.extend({ model: function(params) { this.store.find('event', params.name); } });
ember events.all template
{{#if model}} {{#each model |event| }} <h2>{{#link-to 'events.event' event.name}}{{event.name}}{{/link-to}}</h2> <p>{{event.date}}</p> <p>{{event.location}}</p> <p>{{event.address}}</p> <a href={{event.url}}>read more</a> {{/each}} {{else}}
ember events.event template
{{#each model |item|}} {{item.name}} {{/each}} {{outlet}}
my server response when going /events/eventname is:
{ _id: 55d317d23281dfb23e9ecaa8, url: 'http://gmail.com', timestamp: tue aug 18 2015 07:32:34 gmt-0400 (edt), description: 'another address', address: '123 street', long: 34.234, lat: 12.123, zip: 'h4t3y5', city: 'here', location: 'somewhere', date: mon aug 31 2015 20:00:00 gmt-0400 (edt), name: 'two words', __v: 0 }
the data accurate , changes depending on post click on.
thanks help!
assuming you're using restadapter, server response in wrong format. can read format expects here, response should this:
{ "event": { "id": "55d317d23281dfb23e9ecaa8", "timestamp": "tue aug 18 2015 07:32:34 gmt-0400 (edt)", ... } }
Comments
Post a Comment