【问题标题】:Extjs tree not able to load nested objectExtjs 树无法加载嵌套对象
【发布时间】:2012-08-24 06:48:21
【问题描述】:

我在 java 中有一个名为 Zone1s 的类,它有 2 个字段文本(区域名称)和 Zone1 列表。 当我将其转换为 json 时,我得到以下响应:

{"text":"Papa","Zone1s":[{"text":"Beta1","Zone1s":[{"text":"BetaBeta1","Zone1s":[]},{"text":"BetaBeta2","Zone1s":[]}]},{"text":"Beta2","Zone1s":[]}]}

我在下面写了一个 Extjs 模型、存储和面板:

Ext.define('Zone1s', {
    extend: 'Ext.data.Model',
    fields: [

        { name: 'text', type: 'string' } 
    ], 

    proxy: {                       
        type: 'ajax',
        url : 'test.htm',
        reader: {
    type  : 'json',
      record: 'Zone1s'
        }
    },
hasMany: {model: 'Zone1s', name: 'Zone1s'},
belongsTo: 'Zone1s'
});

var store =Ext.create('Ext.data.Store', {
    model: 'Zone1s',
    autoLoad: true
});

Ext.create('Ext.tree.Panel', {
    title: 'Simple Tree',
    width: 200,
    height: 150,
    store: store,

    renderTo: Ext.getBody()
});

我收到以下错误: me.store.getRootNode 不是函数... 谁能指导我哪里错了? 我经历过 How do I show nested data into a tree? 但在这里,我的 Zone1 本身可以有 Zone1,这就是区别。

【问题讨论】:

    标签: object extjs tree nested


    【解决方案1】:

    你应该给你的 Store 添加一个 root 属性:

    var store =Ext.create('Ext.data.Store', {
        model: 'Zone1s',
        autoLoad: true,
        root: {
          text: 'Zone1s',
          id: 'Zone1s',
          expanded: true
       }
    });
    

    如果您不想看到根节点,请使用 rootVisible 属性:

    Ext.create('Ext.tree.Panel', {
            title: 'Simple Tree',
            width: 200,
            height: 150,
            store: store,
            rootVisible : false,
            renderTo: Ext.getBody()
        });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-04-03
      • 2017-06-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-09-28
      • 1970-01-01
      相关资源
      最近更新 更多