LoginSignup
5
5

More than 5 years have passed since last update.

Backbone.jsで、送信時のパラメータを取得するには

Posted at

fetch()した時のパラメータを保持したい

実装方法

やりかたは下記を参考にしました。
http://d.hatena.ne.jp/heavenshell/20120929/1348885017

    model.fetch({
      // これらはデフォルトパラメータ
      success: _.bind(success, this),
      error: _.bind(failure, this),
      complete: _.bind(complete, this),

      // 受信時に見たいパラメータ
      hoge: hoge_id

    });

ってしとくと、

  // success時の引数optionに設定したパラメータが入る
  success: function(model, resp, option) {

    // 結果表示
    console.log(option.hoge_id, resp);

  },

ということができる。

シチュエーション

送信時の状態と送信結果を対比させたい時や、
同じAPIに対して複数の通信が走る場合等に使えると思います。

5
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
5