最近我一直在使用Dojo的編程應用接口開始,是新來的Dojo和我的第一項任務是創建一個具有行顯示數據庫和文件圖標文件列表中的自定義表部件。該小部件將類似於數據網格,但我們希望使用類似於列表的表格,因爲數據網格有時可能會對網絡造成很大影響。謝謝你的幫助將非常感激。如何在dojo中創建自定義表部件?
0
A
回答
0
好吧,假設你實例化自定義窗口小部件與數據存儲,一樣的網格。您的商店,這取決於哪種類型(例如:itemfilereadstore)有一個郵件列表和下面將對其進行處理,同時創建行到你的widget
<script>
dojo.declare("myTable", [dijit._Templated], {
// define which template to instantiate on your domNode (in this case, table becomes the domNode of your widget)
templateString: '<table><thead dojo-attach-point="headNode"></thead><tbody dojo-attach-point="bodyNode"></tbody></table>',
constructor: function(args) {
args = args || {};
if(!args.store) console.warn("No store supplied");
this.store = args.store
// Note; there are a number of methods to achieve this hook,
// depending on which type of datastore is in use
this.store.fetch({ onComplete: dojo.hitch(this, "_onload") });
},
// function to be called whenever the store has fetched an item set
_onload: function(items) {
var _t = this, store = _t.store, head = _t.headNode, body = _t.bodyNode;
var headIsFilled = false;
// 'haxed' reset of current setup, simply resetting innerhtml
_t.rowIdentifiers = [];
_t.rows = [];
head.innerHTML = "<tr></tr>";
head = head.firstChild;
body.innerHTML = "";
dojo.forEach(items, function(item) {
// generic way of simply showing all of contents available in store
// prefereably, set this structure in an argument while constructing and
// fill head with, say _t.layout
if(!headIsFilled) {
// loops the first item, making sure not to take in any internal references, should check for item
for(var i in item) if(item.hasOwnProperty(i) && i != "_S" && i != "_RI") {
dojo.place("<th>"+i+"</th>");
_t.rowIdentifiers.push(i);
}
headIsFilled = true; // only once
}
var tr = dojo.create("tr", null, body);
var row = { el : tr }
var cell;
dojo.forEach(_t.rowIdentifiers, function(key) {
cell = dojo.create("td", {innerHTML : store.getValue(item, key)}, tr);
row[key] = cell.innerHTML; // the toString value of item
});
_t.rows.push(row);
});
}
});
</script>
代碼尚未評估,但應給予的總體思路如何啓動一個小部件。
注意在代碼中有兩件事情; templateString
是基本的HTML佈局應該是什麼,有一些「神奇」約定,在本例中僅attachpoints用於有_Templated混入使得其domNodes在窗口小部件引用
見下面爲首發教程和一般參考:
http://dojotoolkit.org/documentation/tutorials/1.6/understanding_widget/
http://dojotoolkit.org/documentation/tutorials/1.6/templated/
相關問題
- 1. 創建自定義Dojo小部件
- 2. 如何在dojo工作燈中使用小部件創建自定義列表
- 3. 在dojo中創建自定義StackController
- 4. 無法爲特定屬性創建Dojo自定義小部件
- 5. 如何在以聲明方式創建後檢索自定義Dojo小部件
- 6. 如何從SharePoint 2007中的自定義列表創建自定義Web部件
- 7. 如何在C中的GTK3中創建自定義小部件?
- 8. 如何爲自定義小部件定義自定義getter和setter? - Dojo
- 9. 在自定義小部件中添加dojo小部件
- 10. 如何在ExtJS 4中創建自定義小部件?
- 11. 如何在android中創建自定義小部件
- 12. 如何在自定義ProgressBar小部件中創建TextSwitcher
- 13. 如何在創建DOJO自定義構建時從圖層中排除dojo文件?
- 14. dojo自定義小部件不工作
- 15. 如何在自定義AMD的Dojo小部件
- 16. 在Dojo中創建小部件
- 17. 在Dojo中創建自定義小部件,在新小部件中調用函數的錯誤?
- 18. 建立自定義dojo
- 19. 如何在dojo 1.9中創建表格
- 20. 如何在TFS構建報告中創建自定義部分?
- 21. 創建自定義小部件
- 22. WTForms創建自定義小部件
- 23. 爲Android創建自定義小部件
- 24. 創建自定義類別小部件
- 25. TablelayoutManager,如何創建自定義列表?
- 26. 如何創建自定義表單
- 27. 如何創建自定義的表型
- 28. 如何創建Web部件中自定義列表中插入數據
- 29. 如何在自定義控件中創建名爲valuechanged的自定義事件
- 30. Dojo,如何摧毀一個自定義小部件?
感謝你的幫助,但該數據應被傳遞到通過JSON數據格式,每行的第一列的表中的行應該是一個複選框和第二列我字符串和第三列文件的圖像圖標。 – Ousman
現在,這就是爲什麼有一個與comperators和格渲染/格式功能的網格組件..我不知道爲什麼包裝JSON數據到存儲是一個問題但是,它很容易足以讓你自己'xhr.load(響應){對於eval(響應)中的每個項目構造tr'函數。給出一個你的JSON看起來像什麼的示例,以及如何使用html代碼片段顯示它,並且答案將會出現 – mschr