Javascript extjs数据转换
商店:Javascript extjs数据转换,javascript,json,extjs,extjs4,Javascript,Json,Extjs,Extjs4,商店: Ext.define('firstApp.store.school', { model: 'School', root: 'children', proxy: { type: 'ajax', url: 'http://localhost/firstApp/app/data/school.json', reader: { type: 'json' } }, autoLoad: true }); Ext.define('Sch
Ext.define('firstApp.store.school', {
model: 'School',
root: 'children',
proxy: {
type: 'ajax',
url: 'http://localhost/firstApp/app/data/school.json',
reader: {
type: 'json'
}
},
autoLoad: true
});
Ext.define('School', {
extend: 'Ext.data.Model',
fields: [
{name: 'text', type: 'string'}
]
});
{
"success": true,
"children": [
{"firstName": "Phil", "lastName": "Potato", "leaf": true },
{"firstName": "Nico", "lastName": "Potato", "expanded": true, "children": [
{"firstName": "Mitchell", "lastName": "Potato", "leaf": true }
]},
{ "firstName": "Sue", "lastName": "Potato", "leaf": true }
]
}
型号:
Ext.define('firstApp.store.school', {
model: 'School',
root: 'children',
proxy: {
type: 'ajax',
url: 'http://localhost/firstApp/app/data/school.json',
reader: {
type: 'json'
}
},
autoLoad: true
});
Ext.define('School', {
extend: 'Ext.data.Model',
fields: [
{name: 'text', type: 'string'}
]
});
{
"success": true,
"children": [
{"firstName": "Phil", "lastName": "Potato", "leaf": true },
{"firstName": "Nico", "lastName": "Potato", "expanded": true, "children": [
{"firstName": "Mitchell", "lastName": "Potato", "leaf": true }
]},
{ "firstName": "Sue", "lastName": "Potato", "leaf": true }
]
}
JSON:
Ext.define('firstApp.store.school', {
model: 'School',
root: 'children',
proxy: {
type: 'ajax',
url: 'http://localhost/firstApp/app/data/school.json',
reader: {
type: 'json'
}
},
autoLoad: true
});
Ext.define('School', {
extend: 'Ext.data.Model',
fields: [
{name: 'text', type: 'string'}
]
});
{
"success": true,
"children": [
{"firstName": "Phil", "lastName": "Potato", "leaf": true },
{"firstName": "Nico", "lastName": "Potato", "expanded": true, "children": [
{"firstName": "Mitchell", "lastName": "Potato", "leaf": true }
]},
{ "firstName": "Sue", "lastName": "Potato", "leaf": true }
]
}
我想将JSON文件中的数据转换为学校模型,方法是将模型中的text
与JSON中的firstName+lastName
相等。最近搜索了一些信息,但没有找到任何有用的信息。你能帮我解决这个问题吗 你可以用它
模型:
Ext.define('Dude', {
extend: 'Ext.data.Model',
fields: [
{name: 'fullname', type: 'string'},
{name: 'firstname', mapping: 'name.first'},
{name: 'lastname', mapping: 'name.last'},
{name: 'city', defaultValue: 'unknown'},
'state',
{name: 'text', convert: function(v, record){
!record.data.city ? '' : (record.data.city + ', ' + record.data.state);
}}
]
});