树存储为空-JSON有效吗? [英] Treestore empty - is JSON valid?

查看:71
本文介绍了树存储为空-JSON有效吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

My code looks like this but there is there is no data in the store / tree.

JSON存储有效吗?我需要在JSON顶部的root吗?

Is the JSON store-valid? Do I need a root on top of the JSON?

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

What columns must be defined in the Tree panel?

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 for store
     var oModel = Ext.define('TreeModel', {
        extend: 'Ext.data.Model',
        fields: [
           { name: 'name',         type: 'string' },
           { name: 'path',         type: 'string' }
        ]
     });

商店:

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

TreePanel:

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

推荐答案

您需要在json和读者的根目录中将value更改为children.

You need to change value to children in your json and in the root of your reader.

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

The way to think about is this: The reader's root tells the reader where record data starts. But because tree data is nested (a node can have children) ExtJS looks for another root within each node (then another root within this latter node, and so on recursively).

因此,如果您将读者的根称为子级",则它将在节点中找到具有children节点的子节点.

So if you called your reader's root 'children',it will find the subnodes within a node if it has children node.

您同样可以称其为"subs"或"whatever";您只需确保在整个层次结构中使用相同的东西,包括json数据的根即可.

You could equally call it 'subs', or 'whatever'; you just need to make sure the same thing is used throughout the hierarchy, include the root of the json data.

这篇关于树存储为空-JSON有效吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆