Frage

For example, I have this Model as Users:

var Users = Spine.Model.sub();
Users.configure('Users', 'name', 'gender', 'age');
Users.extend(Spine.Model.Ajax);
Users.extend({url:"/users"});

Assume that we already have some data saved in database. If run

var users = Users.fetch();

Ajax will send a GET request to /users, and all results will be returned.

But if I wanna fetch all female or male users, or age above 25, or top 10 users in specified order, how to pass these variables? I cant find spec in the document. The fetch method can pass a callback function parameter to revoke when fetch complete, clearly not what I want.

War es hilfreich?

Lösung

I found the solution myself..Actually the document tells how to paginate results.

var Photo = Spine.Model.sub();
Photo.configure('Photo', 'index');
Photo.extend(Spine.Model.Ajax);

Photo.extend({
  fetch: function(params){
    if ( !params && Photo.last() ) 
      params = {data: {index: this.last().id}}
    this.constructor.__super__.fetch.call(this, params);
  }
});

But I found the code can't run, first

this.constructor.__super__.fetch.call(this, params);

should be

this.__super__.constructor.fetch.call(this, params);

secondly, if run Photo.fetch({data:{id:1}}), it will send a GET request like this

GET /photos?[object%20Object]

correct it

Photo.fetch({data: $.param({id:1})});

HTTP Request

GET /photos?id=1
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top