2015-02-23 42 views
0

我在dojo上有一個小部件,但它不顯示數據網格。如果我在窗口小部件外部作出示例。我看到了螢火蟲的代碼,但你不能誤會,但我可以看到div檢查,裏面沒有任何東西。 Builder運行,但不加載div中的網格。DataGrid Dojo不能在Widget中工作

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> 
+0

該代碼僅顯示小部件的定義。你如何實例化小部件?你需要實例化這個小部件。例如'var mywidget = new MyWidgetClass()',其中MyWidgetClass是小部件的定義。你也需要在'postCreate'屬性中實例化dojo grid widget,而不是在'constructor'中。作爲domNode的原因將不會準備就緒。 – frank 2015-02-23 16:55:45

+0

我看到按鈕也不起作用。我把構造文章,但不知道如何把MyWidget var = new MyWidgetClass()。這就像道場沒有認爲這個divs,是因爲這個嗎?你可以幫幫我嗎? – user3229393 2015-02-24 14:16:50

回答

0

你需要編寫代碼,你在postCreate功能。

最簡單的方法是將的構造函數關鍵字替換爲postCreate。 原因是「target-node-id」將不會可用,直到postCreate函數調用。

postCreate: function(){ 
    this.inherited(arguments); 
    // Rest of your code here. 
    alert("X"); 
    ... 

}