Created
July 30, 2013 13:08
-
-
Save rmoura-92/6112734 to your computer and use it in GitHub Desktop.
Model nesting
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
define([ | |
'underscore', | |
'backbone', | |
], function(_, Backbone){ | |
var ViagemModel = Backbone.Model.extend({ | |
idAttribute: 'id', | |
initialize: function() { | |
that.getDetalhes(); | |
}, | |
parse: function(response, options) { | |
if(options.detail) { | |
return {detalhes:_.first(response)} | |
} | |
return response; | |
}, | |
getDetalhes: function() { | |
//console.log('ola'); | |
var that = this; | |
var route = 'getMinhasViagensDetail'; | |
var item = this.toJSON(); | |
var params = { | |
pFileNr: item.fileNr, | |
pId: item.id, | |
pType: item.type | |
}; | |
this.fetch({ | |
url: generateUrl(params, route), | |
detail: true, | |
success: function() { | |
//item = model.toJSON(); | |
//that.set({detalhes: item}); | |
that.trigger('complete'); | |
return true; | |
}, | |
error: function() { | |
return false; | |
} | |
}); | |
} | |
}); | |
return ViagemModel; | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
define([ | |
'underscore', | |
'backbone', | |
'models/viagem', | |
], function(_, Backbone, ViagemModel){ | |
var ViagensCollection = Backbone.Collection.extend({ | |
model: ViagemModel, | |
url: function() { | |
return this.model.url; | |
}, | |
parse: function(response, options) { | |
return response; | |
}, | |
getViagens: function(login) { | |
var that = this; | |
var route = 'getMinhasViagens'; | |
this.fetch({ | |
url: generateUrl(login, route), | |
reset: true, | |
success: function(response) { | |
return response; | |
}, | |
error: function() { | |
return false; | |
} | |
}); | |
} | |
}); | |
return ViagensCollection; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment