i am working in extjs4 MVC plus yii framework.I am getting stuck at a point which is how to access extra parameters in jason file coming from server and handle it to client side in extjs4.
My code:-
1) My json file is:–
{
'users': [
{
"userId": 1,
"userName": 'Who will win the series11111111?',
"message":"You are welcome",
}
]
}
2) My userModel class in extjs4 :–
In this file there is no any ‘message’ attribute available.
Ext.define('Balaee.model.sn.UserModel',{
extend: 'Ext.data.Model',
fields: ['userId','userName','password'],
proxy:
{
type:'ajax',
api:
{
read:'http://localhost/balaee/Balaee/index.php?r=SocialNetworking/user/AuthenticateLogin',
create:'http://localhost/balaee/Balaee/index.php?r=SocialNetworking/user/AuthenticateLogin',
},//end of api
reader:
{
type:'json',
root:'users'
},//end of reader
writer:
{
type:'json',
root:'records',
},//End of writer
}//end of proxy
});
3)And here is my view file where I am going to access userName and message fields coming from json file.
Ext.define('Balaee.view...',
{
extend:'Ext.view.View',
store:'kp.UserStore',
config:
{
tpl:'<tpl for=".">'+
'<div id="main">'+
'</br>'+
'<b>userName :-</b> {userName}</br>'+
'<b>message :-</b> {message}</br>'+
'</div>'+
'</tpl>',
itemSelector:'div.main',
}
});// End of login class
But its not working.It display userName field value but not displaying message field value.
Actually I want to access a message field which is not persent in model class in extjs4. Is it correct to access to this type of fields having no any relationship? How can I access this type of fields. Please give me some suggestions.
An
Ext.data.Modelonly knows about the fields it has defined. This is clear from the examples in the documentation.If you want message to be available to your view, it must also be available from your model: