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

converting retrieved models

$
0
0
Hi and good morning, dear friends.

After a long time I did continue developing my project. First step was, to upgrade to JMVC 3.3 due to the fact, that canJS seems to be very tidy.

I have a problem no with converting my models. My service with php-backend delivers the data like this:
  1. {"result":{"loggedin":false},"id":"100","jsonrpc":"2.0"}
where
  1. {"loggedin":false}
is the data. The scaffold around it, is always the same.

The Ajax requests fires not directly by the Model but by a ServiceLayer. I want to be able to change the method by editing only one place.

iuristico/models/model_service_layer.js:
  1. steal('can', function (can) {
  2.     return can.Model(
  3.     /* @static */
  4.     {
  5.                 sequence : 100,
  6.                 model: function( attributes ) {
  7.                               steal.dev.log('model function is fired')
  8.                               return this._super(attributes.result);
  9.                             },
  10.                 models: function( instancesRawData ) {
  11.                               this._super(instancesRawData);
  12.                             else return this._super(instancesRawData.result);
  13.                             },
  14.                 queryfunc : function(id, method, params, success, error){
  15.                     steal.dev.log(this.shortName, this)
  16.                     var modeltype
  17.                     if(method == 'findAll')  modeltype = 'models'
  18.                     else modeltype = 'model'
  19.                     var returninstance = this.shortName.substr(0, 1).toLowerCase() + this.shortName.substr(1)
  20.                     steal.dev.log('returninstance',returninstance)
  21.                     return $.ajax({
  22.                                 async: true,
  23.                                 contentType: 'application/json',
  24.                                 type: 'POST',
  25.                                 processData: false,
  26. //                                dataType: 'json '+returninstance+'.'+modeltype,
  27.                                 dataType: 'json',
  28.                                 url: '/api/v1/jsonrpc.php',
  29.                                 cache: false,
  30.                                 success: function(data){steal.dev.log('success', data)},
  31.                                 error: function(){steal.dev.log('error')},
  32.                                 complete: function(){steal.dev.log('ModelServiceLayer always')},
  33.                                 data: JSON.stringify({jsonrpc : '2.0', method :method, params : new Array(returninstance, params) , id : (this.sequence++)}),
  34.                                 headers: {}
  35.                                     })
  36.                    
  37.                 },
  38.         findOne : function(params, success, error){
  39.                     return this.queryfunc(null, 'findOne', params, success, error)
  40.                 },
  41.     },
  42.     /* @Prototype */
  43.     {});
  44. });
the line
  1. dataType: 'json '+returninstance+'.'+modeltype

did work in the old version but produces an en arror now.


the model looks like

login.js:

  1. steal('iuristico/models/model_service_layer.js', function (modelServiceLayer) {
        return modelServiceLayer.extend('auth',
        /* @static */
        {
        },
        /* @Prototype */
        {});
    });

it is invoked by

  1. this.list.replace(Login.findOne());

in the controller.

everything works fine but the result of the steal.dev.log on success is

  1. { result={loggedin = false}, id="100", jsonrpc="2.0"}

instead of

  1. { loggedin=false}
what am I doing wrong?

Viewing all articles
Browse latest Browse all 3491

Trending Articles