Udo
January 30, 2018, 12:27pm
1
Hey there,
how can I pass some data to an async route?
{
path: '/pageloader/',
async: function (to, from, resolve, reject) {
dataToSend= {};
app.request( {
url: 'php/test.php',
dataType: 'json',
data:dataToSend,
method: "POST",
crossDomain: true,
statusCode: {
404: function(xhr) {
console.log('page not found');
}
},
complete: function() {
console.log('complete');
},
success: function(data) {
console.log('success');
resolve({
template:'<div class="page">{{users}}</div>'
},{
context: {
users:response
}
});
},
error: function() {
console.log('error');
}
});
});
}
i have the same question
path: '/path/', componentUrl: route_root+'/pages/library.html', async(routeTo, routeFrom, resolve, reject) { app.request.json('/ldvx-profile/api-json.php', { controler: 'someController', action: 'someAction', userId: userId, limit: 200 }, function (data) { console.log(data.return); resolve( { template: route_root+'/pages/library.html' }, { context:{ products: data.return}} ); }); }
the data is collected, but the view doesn’t refresh…
You already passing it in context option in resolve call
{
path: '/games/',
async(routeTo, routeFrom, resolve, reject) {
app.request.json('/my/path/api-json.php', { controler: 'someController', action: 'myaction', userId: userId }, function (data) {
resolve({ componentUrl: route_root+'/pages/library.html' }, { context:{ products: data.return}});
});
}
}
and in my html file :
return {
data: function () {
return {
products: this.products,
};
}
};
worked for me.
I’m wondering how to get a preloader component working with this async request.
This is not necessary:
Francois-Xavier_G:
products: this.products,
After you pass it as a context, it is already there.
async(routeTo, routeFrom, resolve, reject) {
app.preloader.show();
app.request.json('/my/path/api-json.php', { controler: 'someController', action: 'myaction', userId: userId }, function (data) {
app.preloader.hide();
resolve({ componentUrl: route_root+'/pages/library.html' }, { context:{ products: data.return}});
});
}
1 Like