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:
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:
{"result":{"loggedin":false},"id":"100","jsonrpc":"2.0"}
{"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:
steal('can', function (can) {
return can.Model(
/* @static */
{
sequence : 100,
model: function( attributes ) {
steal.dev.log('model function is fired')
return this._super(attributes.result);
},
models: function( instancesRawData ) {
this._super(instancesRawData);
else return this._super(instancesRawData.result);
},
queryfunc : function(id, method, params, success, error){
steal.dev.log(this.shortName, this)
var modeltype
if(method == 'findAll') modeltype = 'models'
else modeltype = 'model'
var returninstance = this.shortName.substr(0, 1).toLowerCase() + this.shortName.substr(1)
steal.dev.log('returninstance',returninstance)
return $.ajax({
async: true,
contentType: 'application/json',
type: 'POST',
processData: false,
// dataType: 'json '+returninstance+'.'+modeltype,
dataType: 'json',
url: '/api/v1/jsonrpc.php',
cache: false,
success: function(data){steal.dev.log('success', data)},
error: function(){steal.dev.log('error')},
complete: function(){steal.dev.log('ModelServiceLayer always')},
data: JSON.stringify({jsonrpc : '2.0', method :method, params : new Array(returninstance, params) , id : (this.sequence++)}),
headers: {}
})
},
findOne : function(params, success, error){
return this.queryfunc(null, 'findOne', params, success, error)
},
},
/* @Prototype */
{});
});
the line
dataType: 'json '+returninstance+'.'+modeltype
did work in the old version but produces an en arror now.
the model looks like
login.js:
steal('iuristico/models/model_service_layer.js', function (modelServiceLayer) {
return modelServiceLayer.extend('auth',
/* @static */
{
},
/* @Prototype */
{});
});
it is invoked by
- this.list.replace(Login.findOne());
in the controller.
everything works fine but the result of the steal.dev.log on success is
instead of
what am I doing wrong?