本文介绍了运行dojo dgrid:subrows是未定义的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经尝试使用dgrid(使用他们的示例)为网格布局实现了一个类,但是在加载网格时( subRows is undefined )会收到此错误。我的代码看起来像这样:

  define([
dojo / _base / declare,
dojo / _base / lang,
dgrid / Grid,
dgrid / Keyboard,
dgrid / Selection
],function(
declare ,
lang,
网格,
键盘,
选择
){

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

列:{
first:First Name,
last:Last Name,
age:Age
},
selectionMode:single,// for Selection;只能一次选择一行
cellNavigation:false,//用于键盘;仅允许行级键盘导航

构造函数:function(){
var data = [
{first:Bob,last:Barker,age:89},
{first:Vanna,last:White ,年龄:55},
{first:Pat,last:Sajak,age:65}
];

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

如此调用/创建它

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


解决方案

将您的 code> code into postCreate 方法:

  return declare [网格,键盘,选择],{

列:{
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},
{第一个:Pat,last:Sajak,age:65}
];

this.renderArray(data);
}
});

另请注意 dgrid 不是 dijit 以使其依赖性最小化,因此它没有 placeAt()方法。您有两个选项:


  1. 提供 DOM节点 id 字符串作为第二个参数:

      var gridLayout = new GridLayout({},placeholder); 


  2. 使 dgrid 成为 dijit 通过子类化 dijit / _WidgetBase 使用 gridLayout.placeAt(placeholder)

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



I have tried implementing a class for a grid layout using dgrid (using their sample), but I get this error when loading my grid (subRows is undefined). My code looks something like this:

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

And calling/creating it like this,

app.gridLayout = new GridLayout().placeAt(document.body);
解决方案

Place your constructor code into postCreate method:

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

Also note dgrid is not dijit to minimize its dependencies and therefore it has not placeAt() method. You have two options here:

  1. Provide DOM node or id string of a placeholder to the contructor as a 2nd parameter:

    var gridLayout = new GridLayout({}, "placeholder");
    

  2. Make dgrid to be a dijit via subclassing dijit/_WidgetBase to use gridLayout.placeAt("placeholder"):

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

这篇关于运行dojo dgrid:subrows是未定义的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-11 23:39