如何确保不会使用backbone.js中的历史记录两次创建模型?
在我的路由器中,我有
routes: {
"create/:type": "create",
// #create/modeltype
"diagram/:id": "diagram",
// #diagram/193
"": "list"
//
},
创建路由
create: function(type) {
console.log("diagram create " + type.toUpperCase());
var newDiagram = new Diagram({
type: type.toUpperCase()
});
newDiagram.save({}, {
success: function(model, response) {
console.log("save diagram success");
window.vnb.routers.workspace.navigate("diagram/" + model.get("id"), true);
},
error: function(model, response) {
console.log("error");
console.log(model);
console.log(response);
}
});
},
如果有人创建一个模型然后单击返回,他们会创建另一个模型,我希望这种情况不会发生。
In my router I have
routes: {
"create/:type": "create",
// #create/modeltype
"diagram/:id": "diagram",
// #diagram/193
"": "list"
//
},
then i have the create route
create: function(type) {
console.log("diagram create " + type.toUpperCase());
var newDiagram = new Diagram({
type: type.toUpperCase()
});
newDiagram.save({}, {
success: function(model, response) {
console.log("save diagram success");
window.vnb.routers.workspace.navigate("diagram/" + model.get("id"), true);
},
error: function(model, response) {
console.log("error");
console.log(model);
console.log(response);
}
});
},
If someone creates a model and then clicks back, they create another model, i would like this to not happen.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以将
newDiagram
变量设置为路由器上名为diagram
的属性。然后就可以在第一次调用create方法的时候实例化它,之后对create方法的调用就可以使用该变量了。这是一个例子
You can make the
newDiagram
variable into a property on the router calleddiagram
. Then you can instantiate it the first time the create method is called, and the following calls to the create method can use the variable.Here's an example