我正在尝试从json数据创建一个网格。每个单元最终都是可编辑的。一列包含类型依赖的数据,并根据我想要显示的类型显示一对日期选择器(开始/结束日期)或Textarea或其他小部件。
我正在使用renderCell来呈现这个类型相关的列,但是每当我将Textarea引入到我的代码中时,我就会得到一个错误"TypeError: subRows是未定义的“&只是不能改变它。
我对道场很陌生,所以我想我错过了一些显而易见的东西。我读过所有的文档,尤其是这个post,它对我的情况毫无帮助。不幸的是,许多文档都是代码片&不管是什么,我没有得到的意思是,这些代码片太短,无法开始使用。
有人能帮帮我吗。Textarea是我想要解决的问题,因为这看起来很简单&我还没有尝试正确配置DateTextBox。我想让Textarea开始工作&这会解释剩下的.
我的代码在下面
<html>
<head>
<meta charset="utf-8">
<title>Role assignment</title>
<link rel="stylesheet" href="/library/js/dojo/dojo/resources/dojo.css">
<link rel="stylesheet" href="/library/js/dojo/dgrid/css/dgrid.css">
<link rel="stylesheet" href="/library/js/dojo/dgrid/css/skins/claro.css">
<link rel="stylesheet" href="/library/js/dojo/dijit/themes/dijit.css">
<LINK href="/library/css/custom.css" type="text/css" rel="stylesheet">
<LINK href="/favicon.ico" rel="shortcut icon" type="image/x-icon">
<script type="text/javascript" language="javascript" src="/library/js/script_main.js"></script>
</head>
<body class="claro">
<form>
<div id="grid"></div>
</form>
<!-- load Dojo -->
<script src="/library/js/dojo/dojo/dojo.js"></script>
<script>
require([
'dojo/_base/declare',
'dgrid/Grid',
"dgrid/Selection",
"dgrid/editor",
"dgrid/Keyboard",
"dijit/form/Button",
"dijit/form/Textarea",
"dijit/form/DateTextBox",
"dojo/domReady!"
], function (declare, Grid, Selection, editor, Keyboard, Button, Textarea, DateTextBox) {
var renderRoleData = function(object, value, node, options) {
if (object.role_type == "TIME_RANGE") {
return new DateTextBox();
// no attempt to initialise this yet
}
else if (object.role_type == "MULTI_STRING") {
return new Textarea({
name: "myarea",
value: object.role_data.text,
style: "width:200px;"
});
}
//....more types
}
var columns = [
{
field: 'role_name',
label: 'Role name'
},
{
field: 'role_type',
label: 'Role type'
},
{
field: 'role_enabled',
label: 'Role enabled'
},
{
field: 'role_data',
label: 'Role data',
renderCell: renderRoleData
}
];
var grid = new (declare([ Grid, Selection, editor, Keyboard, Textarea, DateTextBox ]))({
columns: columns,
postCreate: function() {
var data = [
{
"role_dn": "some_ldap_dn1,dc=com",
"role_name": "Water Controller",
"role_type": "TIME_RANGE",
"role_enabled" : true,
"role_data" : {"start_date" : "20150601", "end_date" : "20150701"}
}, {
"role_dn": "some_ldap_dn1,dc=com",
"role_name": "Waste Controller",
"role_type": "MULTI_STRING",
"role_enabled" : true,
"role_data" : { "text": "The reason I need this is very long and complicated. The big long reason is just big and long and honestly you wouldn't care if I told you anwyay" }
}
];
this.renderArray(data);
}
}, 'grid');
});
</script>
</body>
</html>发布于 2015-06-10 19:02:58
最初,我注意到一些可能导致这个问题的问题。相反,请尝试以下几点:
// Dijit widgets should not be mixed into the grid with declare.
// If you're using 0.3, editor should not be mixed in either,
// intended to be applied to specific columns (in 0.4 this is now a mixin).
// Only dgrid mixins should be mixed in via declare.
var CustomGrid = declare([ Grid, Selection, Keyboard ], {
postCreate: function () {
// Call this.inherited to run any postCreate logic in
// previous mixins first
this.inherited(arguments);
var data = [
{
"role_dn": "some_ldap_dn1,dc=com",
"role_name": "Water Controller",
"role_type": "TIME_RANGE",
"role_enabled" : true,
"role_data" : {"start_date" : "20150601", "end_date" : "20150701"}
}, {
"role_dn": "some_ldap_dn1,dc=com",
"role_name": "Waste Controller",
"role_type": "MULTI_STRING",
"role_enabled" : true,
"role_data" : { "text": "The reason I need this is very long and complicated. The big long reason is just big and long and honestly you wouldn't care if I told you anwyay" }
}
];
this.renderArray(data);
}
});
var grid = new CustomGrid({
columns: columns
}, 'grid');declare数组中删除了一些东西,这可能是造成问题的原因。postCreate现在是在直接传递给declare的对象中定义的。该对象的属性将在数组中的构造函数之后混合,而不是在实例化时传递给构造函数的对象的属性,后者将直接覆盖实例上的这些属性。这也使它能够访问调用this.inherited(arguments),这将首先运行任何以前的混合器的postCreate函数。https://stackoverflow.com/questions/30762798
复制相似问题