【问题标题】:Running dojo dgrid : subrows is undefined运行 dojo dgrid : subrows 未定义
【发布时间】:2012-06-18 20:04:47
【问题描述】:

我尝试使用 dgrid(使用他们的示例)为网格布局实现一个类,但在加载我的网格时出现此错误(subRows 未定义)。我的代码如下所示:

define([
    "dojo/_base/declare",
    "dojo/_base/lang",
    "dgrid/Grid",
    "dgrid/Keyboard", 
    "dgrid/Selection"
], function(
    declare,
    lang,
    Grid,
    Keyboard, 
    Selection
){

    return declare([Grid, Keyboard, Selection], {

            columns: {
                first: "First Name",
                last: "Last Name",
                age: "Age"
            },
            selectionMode: "single", // for Selection; only select a single row at a time
            cellNavigation: false, // for Keyboard; allow only row-level keyboard navigation

         constructor: function() {
              var data = [
            { first: "Bob", last: "Barker", age: 89 },
            { first: "Vanna", last: "White", age: 55 },
            { first: "Pat", last: "Sajak", age: 65 }
            ];

            this.renderArray(data);
        }
    });
});

然后像这样调用/创建它,

app.gridLayout = new GridLayout().placeAt(document.body);

【问题讨论】:

    标签: dojo dgrid


    【解决方案1】:

    将您的constructor 代码放入postCreate 方法中:

    return declare([Grid, Keyboard, Selection], {
    
        columns: {
            first: "First Name",
            last: "Last Name",
            age: "Age"
        },
    
        selectionMode: "single",
        cellNavigation: false,
    
        postCreate: function() {
            var data = [
                { first: "Bob", last: "Barker", age: 89},
                { first: "Vanna", last: "White", age: 55},
                { first: "Pat", last: "Sajak", age: 65}
            ];
    
            this.renderArray(data);
        }
    });
    

    还要注意dgrid 不是dijit 以最小化其依赖关系,因此它没有placeAt() 方法。您有两种选择:

    1. 将占位符的 DOM 节点id 字符串 作为第二个参数提供给构造函数:

      var gridLayout = new GridLayout({}, "placeholder");
      
    2. 通过子类化dijit/_WidgetBase 使dgrid 成为一个dijit 以使用gridLayout.placeAt("placeholder")

      declare([_WidgetBase, Grid, Keyboard, Selection], {});
      

    【讨论】:

    • 构造函数和 postCreate 方法有什么区别......甚至是 postMixInPropertie。看起来(根据我的阅读),postCreate 处理小部件上的“最后一分钟”更改,构造函数获取/设置属性/参数(所以大部分时间使用 mixin)。 postMixInPropertie 呢?在渲染之前再次设置小部件上的最后一分钟更改属性..?我有点困惑。
    • dgrid 如何处理存储(例如 json)。我用 JsonRest 和 ObjectStore 尝试了一些东西,但我对 this.renderArray() 对存储的作用有点困惑(查看文档)......我敢打赌我可以解决这个问题。
    猜你喜欢
    • 2013-03-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-09-04
    • 1970-01-01
    • 2013-11-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多