【发布时间】:2015-02-23 15:57:58
【问题描述】:
我在 dojo 上有一个小部件,但它不显示数据网格。如果我在小部件之外制作示例有效。我看的是firebug的代码,你不会弄错的,但是,我可以看到div检查,里面什么都没有。 Builder 运行,但不加载 div 中的网格。
Widget.js
define([ "dojo/_base/declare",
"dojo/text!./FormularioQCI.html",
"icm/base/_BaseWidget",
"dojo/store/JsonRest",
"dojo/store/Memory",
"dojo/store/Cache",
"dojox/grid/DataGrid",
"dojo/data/ObjectStore"
],
function(declare, template, _BaseWidget, JsonRest, Memory, Cache, DataGrid, ObjectStore){
return declare("icm.custom.pgwidget.formularioQCI.FormularioQCIWidget", [_BaseWidget], {
templateString: template,
widgetsInTemplate: true,
constructor: function(){
alert("X");
myStore = dojo.store.Cache(dojo.store.JsonRest({target:"rest/formularioQCI/get"}), dojo.store.Memory());
grid = new dojox.grid.DataGrid({
store: dataStore = dojo.data.ObjectStore({objectStore: myStore}),
structure: [
{name:"State Name", field:"name", width: "200px"},
{name:"Abbreviation", field:"abbreviation", width: "200px", editable: true}
]
}, "target-node-id"); // make sure you have a target HTML element with this id
grid.startup();
alert("Y");
dojo.query("#save").onclick(function(){
alert("X");
dataStore.save();
});
var id = 0;
dojo.query("#add").onclick(function(){
dataStore.newItem({
name: "col2-" + id,
abbreviation: "col3-" + id
});
id++;
});
},
/**
* @private destroys this widget
*/
destroy: function() {
//Do any custom clean up here
this.inherited(arguments);
}
});});
Widget.html
<div style="width: 100%; height: 100%;">
<div id="target-node-id">
</div>
<button id="save">Save
</button>
<button id="add">Add Linha
</button>
</div>
【问题讨论】:
-
代码只显示了小部件的定义。你是如何实例化小部件的?您需要实例化小部件。例如
var mywidget = new MyWidgetClass()其中 MyWidgetClass 是小部件的定义。您还需要在postCreate属性中而不是constructor中实例化dojo 网格小部件。原因是 domNode 到那时还没有准备好。 -
我看到按钮也不起作用。我把构造贴出来但是不知道怎么把MyWidget var = new MyWidgetClass()。好像dojo没想到div,是因为这个吗?你能帮帮我吗?
标签: dojo widget dojox.grid.datagrid