Skip to content

Instantly share code, notes, and snippets.

@Bondifrench
Last active August 29, 2015 14:23
Show Gist options
  • Save Bondifrench/cbedf7ea3f0d11b9ea22 to your computer and use it in GitHub Desktop.
Save Bondifrench/cbedf7ea3f0d11b9ea22 to your computer and use it in GitHub Desktop.
Problem with m.request and background
/**
* 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