gpt4 book ai didi

javascript - Ext JS数据转换

转载 作者:行者123 更新时间:2023-12-02 15:43:06 25 4
gpt4 key购买 nike

商店:

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'}
]
});

JSON:

{
"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 }
]
}

我想通过使模型中的 text 等于 JSON 中的 firstName + lastName 来将 JSON 文件中的数据转换为 School 模型。最近搜索了一些信息,但没有找到任何帮助。你能帮我解决这个问题吗?

最佳答案

您可以使用convert为此。

型号:

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);
}}
]
});

关于javascript - Ext JS数据转换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32433376/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com