jeudi 12 juin 2014

How to get the filed value of Module's Object?

Dear:

I get it , I must use x.data.name;

but , another question is, Use Proxy



Code:



<script type="text/jscript">
Ext.require(['Ext.grid.*', 'Ext.data.*' ]);
var x;
Ext.onReady(function(){

Ext.define('Student', {
extend: 'Ext.data.Model',
fields:[{name:"id",type:"string"},
{name:"name",type:"string"},
{name:"class",type:"string",convert:function(val){
if(val=="1"){return "A"};
if(val=="2"){return "B"};
if(val=="3"){return "C"}; }
}
],
proxy: {type: 'ajax',
url: '4.15b.json',
reader: {
type: 'json',
root: 'items',
//totalProperty : 'total'
}
},
autoLoad: true

});


x = Ext.ModelManager.getModel('Student');

//Uses the configured RestProxy to make a GET request to /users/123
x.load("002", {
success: function(user) {
console.log(user.data.name); //logs 123
// alert(user.getName());
}
});


})
</script>

4.15b.json :


Code:



{
items: [
{id:"001",name: "PA",class:"1"},
{id:"002",name:"LP",class:"2"},
{id:"003",name: "GY",class:"1"}
]
}

Q1. Does the load 1st param , must use id? or the column name must id?

Q2.i Load 002, but its still show PA (001's name)?

thx


Aucun commentaire:

Enregistrer un commentaire