K
K
kid-programmer2015-05-07 17:25:00
JavaScript
kid-programmer, 2015-05-07 17:25:00

Ember how to update model after creation?

I create a post

var newPost = this.store.createRecord("post", {
                title: this.get("title"),
                text: this.get("text"),
                intro: this.get("intro")
            });
            newPost.save();         
            this.transitionToRoute("admin.posts");

after creation, go to the page for displaying all posts, the route says
App.AdminPostsRoute = Ember.Route.extend({
    model: function () {
        return this.store.find("post");
    }
});

A new post appears on the page but without Id and other properties that the server hangs up, how to update the model after creation?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Stanislav Romanov, 2015-05-07
@kid-programmer

Apparently, the fact is that you go to another page even when the request has not been completed, try this:

var newPost = this.store.createRecord("post", {
                title: this.get("title"),
                text: this.get("text"),
                intro: this.get("intro")
            });
            var _this = this;
            newPost.save().then(function() {
                _this.transitionToRoute("admin.posts");
            });

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question