Quantcast
Channel: JavaScriptMVC Forum
Viewing all articles
Browse latest Browse all 3491

How to correctly implement findAll method with custom server response (paginated)

$
0
0
I am using one rest framework that will reproduce following result:

  1. {
  2.     count: 10
  3.     results: [
  4.         { id: 1 }, 
  5.         { id: 2 }, 
  6.         { id: 3 }
  7.     ]
  8. }

I need to adapt this custom server response to findAll method. I have tried following code but didn't work.

  1. var Asset = can.Model.extend(
  2. /* @static */
  3. {
  4.      findAll : "GET /feed/",
  5. },
  6. /* @Prototype */
  7. { }
  8. );
  9. Asset.List = can.Model.extend({
  10. },
  11. {
  12.     findAll: function(params, success, error) { 
  13.         var self = this;
  14.         // Uncaught TypeError: Object #<Constructor> has no method 'model'
  15.         this.model().findAll(params, function(items) {
  16.             self.push(items.results);
  17.         
  18.             if (success) {
  19.                 success(self);
  20.             }
  21.         }, error);
  22.     }
  23. })
My usage code

  1. new Asset.List().findAll({});

In the findAll method, this.model raises error, anyone knows about that? Thanks!

Viewing all articles
Browse latest Browse all 3491

Trending Articles