0

In a separate view in backbone I have a function that basically creates a new post:

save : function(){
    console.log($('#big-input').val());
    console.log(window.id);
    this.collection.create({
        name: $('#big-input').val(),
        adress: $('small-input').val(),
        postedBy: window.id
    });
    //navigate to that post     
},

In another view all the views are listed, and if the user clicks one of these views the uri changes to "#post/:id"

and in my roots I have this:

routes: {
    "" : "showForm",
    "post/:id" : "showPost"
},


showPost: function(id){

    var curmodel = this.collection.get(id);
    console.log(curmodel);
    var posts = new postView({model:curmodel});
    posts.render();
    $(".maincontainer").html(posts.el);

},

I am having no problem to navigate to any of these posts from this list of posts, my router handles them very well, but I am having a problem navigating to the post that I just created after creating possibly inside the save function..

4

1 回答 1

0

您确定在通过路由访问之前将新模型保存到服务器吗?

可以肯定的是,如果您想在将新模型添加到集合之前等待服务器,则始终可以将 {wait: true} 传递给 create()。

例子:

this.collection.create({
        name: $('#big-input').val(),
        adress: $('small-input').val(),
        postedBy: window.id
    }, {wait:true});
于 2013-08-02T22:39:40.213 回答