Skip to content

Instantly share code, notes, and snippets.

@megalithic
Last active August 29, 2015 14:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save megalithic/fec3d38cfbb560e98cc8 to your computer and use it in GitHub Desktop.
Save megalithic/fec3d38cfbb560e98cc8 to your computer and use it in GitHub Desktop.
ampersand view, having a time with model data fetching and binding
var AmpersandModel = require('ampersand-model');
var config = require('clientconfig');
var Status = require('./status');
var StatusModel = new Status();
var ItineraryModel = AmpersandModel.extend({
props: {
uuid: ['string', true, ''],
userId: ['string', true, ''],
expiredAt: ['string', true, ''],
items: ['array', true, function() { return []; }]
},
children: {
status: Status
},
urlRoot: config.apiUrl + '/itinerary',
ajaxConfig: function() {
return {
xhrFields: {
responseType: "json"
},
useXDR: true
}
}
});
module.exports = ItineraryModel;
var PageView = require('./base');
var templates = require('../templates');
module.exports = PageView.extend({
prop: {
status: 'object'
},
autoRender: false,
pageTitle: 'my itinerary',
template: templates.pages.myItinerary,
bindings: {
'model.status.message': '[data-hook~=status-message]',
'model.status.code': '[data-hook~=status-code]'
},
render: function () {
this.renderWithTemplate();
this.fetchItinerary();
},
fetchItinerary: function () {
this.model.fetch();
this.model.status.fetch();
return false;
},
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment