Treestore 为空 - JSON 有效吗?

2024-01-12

我的代码看起来像这样,但商店/树中没有数据。

JSON 存储有效吗?我需要一个root在 JSON 之上?

必须在“树”面板中定义哪些列?

JSON:

{
   "status" : {
      "status" : 0,
      "msg" : "Ok",
      "protocolversion" : "1.1.json"
   },
   "value" : {
      "name" : "Root",
      "path" : "\/",
      "leaf" : false,
      "children" : [
            {
               "name" : "subfolder1",
               "path" : "\/subfolder1",
               "leaf" : false,
               "children" : []
            },
            {
               "name" : "subfolder2",
               "path" : "\/subfolder2",
               "leaf" : false,
               "children" : []
            },
            {
               "name" : "report1",
               "path" : "\/report1",
               "leaf" : true,
               "children" : []
            }
         ]
   }
}

我的 ExtJs 代码:

Model:

// Model for store
     var oModel = Ext.define('TreeModel', {
        extend: 'Ext.data.Model',
        fields: [
           { name: 'name',         type: 'string' },
           { name: 'path',         type: 'string' }
        ]
     });

Store:

     // Store with local proxy
     var oStore = Ext.create('Ext.data.TreeStore', {
        model: oModel,
        autoLoad: true,
        proxy: {
           type  : 'ajax',
           url   : './data/response.json'
        },
        reader: {
           type  : 'json',
           root  : 'value'
        }
     }); 

树面板:

     // View with TreePanel
     var oTreePanel = Ext.create( 'Ext.tree.Panel', {
        store       : oStore,
        useArrows   : true,
        displayField: 'text',
        rootVisible : true,
        multiSelect : true,
        border      : 0,
        columns     : [
           {
              xtype    : 'treecolumn',
              dataIndex: 'name',
              text     : 'Tree',
              flex     : 3
           },
           {
              dataIndex: 'path',
              text     : 'Path',
              flex     : 2
           }
        ]
     } );

你需要改变value to children在你的 json 和阅读器的根目录中。

思考的方式是这样的:读者的根告诉读者记录数据从哪里开始。但是因为树数据是嵌套的(一个节点可以有子节点),ExtJS 在每个节点内查找另一个根(然后在后一个节点内查找另一个根,依此类推)。

因此,如果您将阅读器的根称为“子节点”,它会查找节点内的子节点(如果有)children node.

您同样可以将其称为“subs”或“whatever”;您只需要确保整个层次结构中使用相同的内容,包括 json 数据的根。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Treestore 为空 - JSON 有效吗? 的相关文章

随机推荐