0

切り替えることができるタブが3つあります。タブの1つとして、コントローラーに送信できるフォーム/ビューをバックボーンで生成します。問題は、タブを切り替えて、フォームを生成するタブをクリックしてから[送信]をクリックすると、コントローラーに複数のAJAX呼び出しを送信することです。

    addPlace: function(e) {
      if(!this.isSearch){
        this.add = new add({
          model: this.model,
          attachPoint: this.$("div.addAPlaceForm")
        });
        $('.add_to_place').addClass("hidden");
        $('.matchingWrapper').addClass("hidden");
        this.add.render();
        this.add.on("place:selected", this.placeSelect, this);
        this.isSearch = true;
      } 
    }

    //this.add.render()
    render: function(e){
      this.$el.html(this.addPlaceForm({
        place: this.model
      }));  
      view.prototype.render.call(this);
  }

ユーザーがフォームを生成しない他のタブの1つに切り替えると、次の機能が実行されます。

   addPlacebacklink: function(e) {
        this.add.undelegateEvents();
        this.add.unbind();

        $("div.addAPlaceForm").html("");
        this.isSearch = false;
    }

私はあなたがそうすることになっていることを読みましたunbindundelegateEventsしかし、私はまだ私のコントローラーへの複数のAJAX呼び出しを見ます。タブを複数回切り替えても1つのフォームのみを送信できるようにBackboneを設定するにはどうすればよいですか?

4

1 に答える 1

0

実際にコードをリファクタリングして this.add をチェックし、タブを切り替えるとフォームを非表示にしました。

addPlace: function(e) {
  if(!this.add){
    this.add = new add({
      model: this.model,
      attachPoint: this.$("div.addAPlaceForm")
      this.add.render();
      this.add.on("place:selected", this.placeSelect, this);
    });
    this.$('.add_to_place').addClass("hidden");
    this.$('.matchingWrapper').addClass("hidden");
    this.$(".form-horizontal").removeClass("hidden");

  } 
}


addPlacebacklink: function(e) {
     this.$(".form-horizontal").addClass("hidden");
}
于 2013-02-20T03:40:51.363 に答える