samedi 14 juin 2014

Load session user into viewModel

Is there a way to autoload model into view model, kinda like with stores? Let's say I want to linkTo() session User without specifying id? Can we use Ext.Direct function to fetch the user record?

Code:



Ext.define('APP.view.main.MainModel', {
extend: 'Ext.app.ViewModel',

alias: 'viewmodel.app-main',

links: {
// gives Cannot load phantom model
user: {
reference: 'User',
type: 'session'
},
// can we do this?
sessionUser: {
reference: 'User',
fn: 'APP.api.User.readSession'
}
}

});

For now, I am loading user manually like this ...

Code:



APP.api.User.readSession(function(result){
if (result.success) {
var user = Ext.create('APP.model.User', result.data);
this.getView().getViewModel().set('user', user);
}
}, this);

Furthermore, it takes a few moments for the value to be binded and it flickers. How can we bind dynamic values before view is rendered? Or how can we wait for initial bind to take place?


Aucun commentaire:

Enregistrer un commentaire