PDA

View Full Version : How to get the filed value of Module's Object?



softball
12 Jun 2014, 12:18 AM
dear ?
How to get the filed value of Module's Object?
as the code.

I had try x['name'] or x.name?
But it does't work.


var x;
Ext.onReady(function(){

Ext.define('Student', {
extend: 'Ext.data.Model',
fields:[{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"}; }
}
]
});

/*
x=new Student({ name:"test",class:"3"});
console.log(x);
*/

x=Ext.create('Student',{
proxy: {
type: 'ajax',
url: '4.15a.json',
reader: {
type: 'json',
root: 'items',
//totalProperty : 'total'
}
},
autoLoad: true
});
})

softball
12 Jun 2014, 1:17 AM
Dear? I get it ? I must use x.data.name; but , another question is, Use Proxy
4.15b.json ? [code] { items: [ {id:"001",name: "PA",class:"1"}, {id:"002",name:"LP",class:"2"}, {id:"003",name: "GY",class:"1"} ] } [/cdoe] 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

softball
12 Jun 2014, 1:19 AM
Dear?
I get it ? I must use x.data.name;

but , another question is, Use Proxy


<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 ?


{
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