2012-01-18 7 views
0

私はbackbone.jsで履歴を使用してモデルを2回作成しないようにするにはどうすればよいですか?私のルータで

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); 
      } 
     }); 

    }, 

を作成しています。

答えて

0

newDiagram変数をルータ上のdiagramという名前のプロパティにすることができます。次に、createメソッドが初めて呼び出されたときにそのインスタンスをインスタンス化することができ、createメソッドへの次の呼び出しでその変数を使用できます。

は、ここでは一例

create: function(type) { 
    console.log("diagram create " + type.toUpperCase()); 

    if (this.diagram === undefined) { 
     this.diagram = new Diagram({ 
      type: type.toUpperCase() 
     }); 
    } 

    this.diagram.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); 
     } 
    }); 

}, 
+0

おかげでポールだが、そのはなく、かなり私が欲しいもの、これは私が新しい図を作成することはできませんを意味します。私は、ルータの履歴スタックから作成ルートを削除したいだけです。 –