我正在创建一个动态的GridContainer。但是,发生了错误。 console.log输出正确的值输出。但是,执行错误。我不明白这种情况。
我的代码。
define([ "dojo/parser", "dojo/dom", "dojo/dom-style",
"dijit/registry","dojo/on", "dojo/request", "dojo/dom-construct","dojo/json",
"dojo/_base/array", "dijit/Dialog","dijit/focus" ,"dijit/form/Button","dijit/form/Select","dijit/form/TextBox",
"dijit/form/CheckBox", "dojo/query","dojox/layout/GridContainer","dojox/widget/Portlet","dijit/layout/BorderContainer",
"dijit/layout/TabContainer", "dijit/layout/ContentPane"], function(parser, dom, domStyle,
registry,on, request, domConstruct,json, arrayUtil, Dialog,focus,Button, CheckBox,query,GridContainer,Portlet) {
function addTab(formCount,num){//make gridContainer ajax
var xhrArgs = {
url: '/checkData',
handleAs: "json",
content:{
seq:num
},
load:function(data){
var cont='';
++gridCounter;
cont+='<div dojoType="dojox.layout.GridContainer" class="test" doLayout="true" id="gc'+gridCounter+'" region="center" hasResizableColumns="false" opacity="0.3" nbZones="1" allowAutoScroll="false" withHandles="true" dragHandleClass="dijitTitlePaneTitle" minChildWidth="200" minColWidth="10" style="height:50%;">';
..........
}
}
function addGridContainer(id){
alert('vidgetAddgridNo:'+id);
var result='';
var xhrArgs = {
url: '/checkVidget',
handleAs: "json",
content:{
id:id
},
load: function(data){
++addPorNum;
result+=data;
var portletContent2 = [
domConstruct.create('div', {innerHTML: result})
];
var portlet2 = Portlet({
id: 'dynPortlet'+addPorNum,
closable: false,
title: ''+result,
content: portletContent2
});
makeGrid(portlet2);
}
}//end xhrArgs
var deferred = dojo.xhrGet(xhrArgs);
function makeGrid(por){
console.log('makeGrid in');
var selectedTab=registry.byId('tabContainer').get('selectedChildWidget');
var tabs=registry.byId("tabContainer");
var cPane=tabs.get("selectedChildWidget");
var grid=cPane.getChildren()[0];
var id=grid.id;
alert(registry.byId(id));=>[Widget dojox.layout.GridContainer,gc1]
registry.byId(id).addChild(por,0,0);=>Error:Cannot set property 'id' of undefined
}//end makeGrid()
}
请帮助我... T.T
答案 0 :(得分:1)
在define()
模块列表中,您定义了以下模块:
"dijit/form/Button", "dijit/form/Select", "dijit/form/TextBox",
"dijit/form/CheckBox"
但是,在你的回调中你只有:
Button, CheckBox
因此,您在这里错过了Select
和TextBox
模块,这意味着参数CheckBox
实际上包含模块dijit/form/Select
。这意味着每个模块都被移动,并且它们都没有包含实际值,请先尝试修复它。