鈍足ランナーのIT日記

走るのが好きな5流のITエンジニアのブログ。

趣味の範囲は広いけど、どれも中途半端なクソブロガー楽しめるWebアプリを作ってあっと言わせたい。サーバーサイドPerl(Mojolicious)、クライアントサイドVue.js。Arduinoにも触手を伸ばす予定。

Backbone.js の Collection(Paginator.requestPager)に属性を追加したい

I'm using Paginator.requestPager in backbone. And I wanted to change query paremeter value at time Collection fetch is called. So, I added setDefaults function in Equipments. But in this case Backbone.Paginator 's setDefault function will not be called. How to add some attribute's in Paginator requestPager?

My javascript ability is poor. Oh no..

var Equipments = Backbone.Paginator.requestPager.extend({
  model: Equipment,
  setDefault: function(){
      this.query = "test";
  }

追記-自己解決

I dont have to overwide setdefault function, I only have to add function to set property like this.

var Equipments = Backbone.Paginator.requestPager.extend({
  model: Equipment,
  setQuery: function(value){
      this.query = value;
  }

And I add Collection view. subscribe "reset" event. and I solved all problems.

var EquipmentsView = Backbone.View.extend({
    el: '#equipments_view',
    initialize: function() {
        this.render();
        this.listenTo(this.collection,"reset",this.render);
    },