Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript extjs数据转换_Javascript_Json_Extjs_Extjs4 - Fatal编程技术网

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