Last active
August 29, 2015 14:23
-
-
Save Bondifrench/cbedf7ea3f0d11b9ea22 to your computer and use it in GitHub Desktop.
Problem with m.request and background
This file contains hidden or 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
/** | |
* This version works | |
**/ | |
var dashboard = {}; | |
dashboard.model = function(id) { | |
return m.request({ | |
method: 'GET', | |
url: window.location.origin + '/example/' + id, | |
}) | |
} | |
dashboard.controller = function() { | |
var ctrl = this; | |
ctrl.exa = m.prop(535); | |
ctrl.data = dashboard.model(ctrl.exa()) | |
} | |
dashboard.view = function(ctrl) { | |
return [ | |
m('.wrapper', [ | |
m('.container', [ | |
m('table.table.table-hover', [ | |
m('thead', [ | |
m('tr', [ | |
m('th.text-center', 'Fiscal Year'), | |
m('th', 'Report type'), | |
m('th', 'Date'), | |
m('th', 'Reports') | |
]) | |
]), | |
m('tbody', [ | |
ctrl.data().rows.map(function(item) { | |
return m('tr', [ | |
m('td.text-center', item.Year), | |
m('td', item.reportType), | |
m('td', item.Date), | |
m('td', [ | |
m('a', { | |
href: '/reports/' + item.ReportId, | |
target: '_blank' | |
}, 'Reports'), | |
]) | |
]) | |
}) | |
]) | |
]) | |
]) | |
]) | |
] | |
} | |
/** | |
* This version with background: true doesn't work | |
**/ | |
var dashboard = {}; | |
dashboard.model = function(id) { | |
return m.request({ | |
method: 'GET', | |
url: window.location.origin + '/example/' + id, | |
background: true, | |
initialValue: []} | |
}).then(function() { | |
m.redraw() | |
}) | |
} | |
dashboard.controller = function() { | |
var ctrl = this; | |
ctrl.exa = m.prop(535); | |
ctrl.data = dashboard.model(ctrl.exa()) | |
} | |
dashboard.view = function(ctrl) { | |
return [ | |
m('.wrapper', [ | |
m('.container', [ | |
m('table.table.table-hover', [ | |
m('thead', [ | |
m('tr', [ | |
m('th.text-center', 'Fiscal Year'), | |
m('th', 'Report type'), | |
m('th', 'Date'), | |
m('th', 'Reports') | |
]) | |
]), | |
m('tbody', [ | |
ctrl.data().rows.map(function(item) { | |
return m('tr', [ | |
m('td.text-center', item.Year), | |
m('td', item.reportType), | |
m('td', item.Date), | |
m('td', [ | |
m('a', { | |
href: '/reports/' + item.ReportId, | |
target: '_blank' | |
}, 'Reports'), | |
]) | |
]) | |
}) | |
]) | |
]) | |
]) | |
]) | |
] | |
} | |
/** | |
* This version doesn't work either' | |
**/ | |
var dashboard = {}; | |
dashboard.model = function(id) { | |
return m.request({ | |
method: 'GET', | |
url: window.location.origin + '/example/' + id, | |
background: true, | |
initialValue: []} | |
}) | |
} | |
dashboard.controller = function() { | |
var ctrl = this; | |
ctrl.exa = m.prop(535); | |
ctrl.data = dashboard.model(ctrl.exa()).then(function() { | |
m.redraw() | |
}) | |
} | |
dashboard.view = function(ctrl) { | |
return [ | |
m('.wrapper', [ | |
m('.container', [ | |
m('table.table.table-hover', [ | |
m('thead', [ | |
m('tr', [ | |
m('th.text-center', 'Fiscal Year'), | |
m('th', 'Report type'), | |
m('th', 'Date'), | |
m('th', 'Reports') | |
]) | |
]), | |
m('tbody', [ | |
ctrl.data().rows.map(function(item) { | |
return m('tr', [ | |
m('td.text-center', item.Year), | |
m('td', item.reportType), | |
m('td', item.Date), | |
m('td', [ | |
m('a', { | |
href: '/reports/' + item.ReportId, | |
target: '_blank' | |
}, 'Reports'), | |
]) | |
]) | |
}) | |
]) | |
]) | |
]) | |
]) | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment