Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/extjs/3.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
Extjs 包含加载存储中嵌套数据的网格行_Extjs_Extjs4 - Fatal编程技术网

Extjs 包含加载存储中嵌套数据的网格行

Extjs 包含加载存储中嵌套数据的网格行,extjs,extjs4,Extjs,Extjs4,我有一个加载了参数的dataview。我在模板中呈现这些数据。我尝试使用相同的数据,其中有一个嵌套项要渲染到网格 数据如下所示: { "myJson": { "name": "abc", "type": "faulty", "notes": [ { "date": "01-01-1970", "note": "test note"

我有一个加载了参数的dataview。我在模板中呈现这些数据。我尝试使用相同的数据,其中有一个嵌套项要渲染到网格

数据如下所示:

{
    "myJson": {
        "name": "abc",
        "type": "faulty",
        "notes": [
            {
                "date": "01-01-1970",
                "note": "test note"
            },
            {
                "date": "01-02-1970",
                "note": "test note 2"
            }
        ]
    }
}
商店:

proxy: {
                type: 'ajax',
                url: '/api/detail/',
                reader: {
                    type: 'json',
                    root: 'myJson'
                }
            }
型号:

    {
        name:'name',
    },
    {
        name:'type',
    },
    {
        name:'notes',
        mapping:'notes'
    },
模板:

{name} - {type}
这一切都有效。我想做的是使用
notes
块在网格中显示。问题是我无法让它阅读笔记组

var notesListView = new Ext.list.ListView({
    store: 'myStore',
    multiSelect: false,
    width:'100%',
    id:'notesList',
    columns: [{
        header: 'Date',
        width: 75,
        dataIndex: 'date'
    },{
        header: 'Note',
        width: 150,
        dataIndex: 'note',
    }]
});
甚至有可能做到这一点吗?或者我需要创建一个新的存储和模型来在网格中使用这组数据吗

例如,我尝试在两个模型中映射到notes.date

name:'note_date',
mapping:'notes.date'
在网格中

dataIndex:'notes.date'
两者都不起作用

我也尝试过使用
渲染器
,但这也不起作用,因为它是一个数组

renderer:function(value, metaData, record, rowIndex, colIndex, store){
    var value = value.date;//won't work; it needs an index a la value[0].date
    return value;
}

可以使用接收到的相同数据创建嵌套模型。是这样的

Ext.define("JsonModel", {
  extend: 'Ext.data.Model',
  fields: ['name','type'],
  hasMany: [{
      model: 'Note',
      name: 'notes'
  }]
});

Ext.define("Note", {
  extend: 'Ext.data.Model',
  fields: [
      'date',
      'note']
});
通过这种方式,您可以访问任何这样的give记录的子项

var jsonRecordChildren = jsronRecord.notes()
我刚刚创建的变量jsonRecordChildren的类型是Store,因此您可以轻松地将其分配给网格的属性存储

Ext.create('Ext.grid.Panel', {
  store: selectedRecord.notes(),
  columns: [
      { text: 'Date',  dataIndex: 'date' },
      { text: 'Note', dataIndex: 'note'}
  ],
  renderTo: Ext.getBody()
});

因为两者都不正确。您不能参考
notes.date
,因为
notes
是一个数组。谢谢帮助:/谢谢您的回复。还有小提琴。但愿它没有涉及太多,因为我似乎永远无法让这些工作。。。在小提琴中工作,但在使用ajax代理的应用程序中,无论我如何尝试,应用程序都找不到notes():这可能会对您有所帮助。嘿,谢谢:)我尽了我的努力;在抱怨我没能得到它之前,我对许多帖子感到困惑。不知道是因为模型和存储在嵌套文件夹中还是什么原因。尝试了我能找到的所有建议(甚至尝试将代理移动到模型中)。当我记录selectedRecord时,控制台会记录一个构造函数(缺少notesStore),而在fiddle中,它会记录一个存储完整的对象。chrome控制台会给你一个错误吗?json的notes节点的name属性是否与json的notes节点匹配?你的模型上膛了吗?。你能拆开我做的JSFIDLE让它看起来更像你的代码吗?我不认为ajax代理是问题所在,但有一种方法可以在JSFIDLE中模拟它。错误是类似于
Object[Object]没有方法“notes”
的。正如我所说,模型和商店嵌套在文件夹中,并被称为类似于“MyApp.model.People.Notes”。hasMany名称与notes节点匹配,但找不到notes()。另一个很大的区别是,存储是通过onChange在另一个元素上加载参数的。我试图在存储加载的成功回调上调用此网格代码,它启动了,但getAt(0)似乎总是返回一个构造函数sans notes()。最后我做了些别的事情,但我真的很感谢你的帮助:)