ember.js - Trouble with transitionTo route after adding a new record using ember data and Parse -


i'm learning ember , ember data extending example blog app ember guides page, , having difficulty implementing "new" route adding new blog entries. i'm using ember data adapter parse persist data. have connected parse , can query , update records in parse. created "new" route , can create new post, have 2 problems:

1) route new posts adds post on parse, won't redirect post route after has been saved. gives me error "uncaught error: assertion failed: cannot call 'id' on undefined object.". i've tried variations of transitionto('posts.post') , other options stumped on how redirect post detail new post. here's postsnewroute:

app.postsnewroute = ember.route.extend({     model: function() {         return app.post.createrecord();     },     events: {         createpost: function() {         this.get('store').commit();         this.transitionto('post');         }     } }); 

2) type in title of new post, shows in posts list, sample app. however, when click create, persists record parse, , adds parse record list too. first post added has null id, , 2nd duplicate post has post id parse. if click on 2nd duplicate post, displays want, new post in post detail view. how rid of duplicate post in list, , how redirect go straight detail of new post? reference, router below

app.router.map(function() {     this.resource('posts', function() {         this.resource('post', { path: ':post_id'});         this.route('new')     });     this.resource('about'); }); 

you want transition post route after commit has returned server, think. i'm not sure if commit returns promise or not (i'm not on latest version of ed)

if yes, can use promise's then function transition on success.

this.get('store').commit().then(function(post) {   this.transitionto('posts.post', post); }); 

if no, can bind action post record's id changes, i.e. comes server, can call transition then. assuming post object.

post.addobserver('id', post, '_transitionfunction') 

and then:

_transitionfunction: function() {   var post = // handle post object;   post.removeobserver('id', this, '_transitionfunction');   this.transitionto('posts.post, post); } 

these examples aren't entirely accurate (i in controller, not route, let me know if need more clarification.

you can see implementation here.


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -