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

models not been converted

$
0
0
Hey guys, i have the following code but i cant seem to get the response converted into appropriate model instances.... if anyone could help would be appreciated

can.fixture("GET /fabz", function () {
  return { id:1, name:"name", fabby: { name: 'subname'}};
});
/*can.$.ajax({url:"/fabz",type:"get",success:function(){
  console.log("arguments:",arguments);
}});*/
Fab = can.Model.extend('Fab', {
  parseModel: function (data) {
    var _fab = new Leo(data);
    console.log('Leo:parseModel data:', data, '_fab:', _fab);
    return _fab;
  },
  findOne: function(ajaxoptions) {
    return $.ajax(ajaxoptions);
  }
}, {
  init: function () {
    console.log('Fab:init');
  }
});
Leo = can.Model.extend('Leo', {
  parseModel: function (data) {
    var _leo = new Leo(data);
    console.log('Leo:parseModel data:', data, '_leo:', _leo);
    return _leo;
  },
  findOne: function(ajaxoptions) {
    return $.ajax(ajaxoptions);
  }
}, {
  init: function (data) {
    console.log('Leo:init');
  },
  define: {
    fabby: {
      type: Fab.parseModel
    }
  }
});
Leo.findOne({
  url: '/fabz',
  type: 'GET',
  success: function (data) {
    console.log('Leo.findOne success:', arguments, 'data:',data);
    
  },
  error: function () {
    console.log('error:', arguments);
  }
}).done(function(){ console.log('Leo.findOne.done arguments:',arguments); });


Viewing all articles
Browse latest Browse all 3491

Trending Articles