我将使用标准操作按钮(添加,编辑,删除,刷新)创建新的类工具栏。我为此写了一个简单的类:
define([
"dojo/_base/declare",
"dijit/_WidgetBase",
"dijit/_TemplatedMixin",
"dijit/_WidgetsInTemplateMixin",
"dijit/Toolbar",
// Template for new widget
"dojo/text!/ui/widgets/StandardToolbar.html",
// Load dijit/form/Button widget as dependency for parsing template
"dijit/form/Button"
], function(declare, _WidgetBase, _TemplatedMixin, _WidgetsInTemplateMixin, Toolbar, templateString){
return declare("app.StandardToolbar", [
_WidgetBase,
_TemplatedMixin,
_WidgetsInTemplateMixin,
Toolbar
], {
templateString: templateString
});
});
从基本工具栏扩展的模板:
<div class="dijit" role="toolbar" tabIndex="${tabIndex}" data-dojo-attach-point="containerNode">
<button data-dojo-type="dijit/form/Button" data-dojo-attach-point="addButton">Add</button>
<button data-dojo-type="dijit/form/Button" data-dojo-attach-point="editButton">Edit</button>
<button data-dojo-type="dijit/form/Button" data-dojo-attach-point="removeButton">Remove</button>
<button data-dojo-type="dijit/form/Button" data-dojo-attach-point="refreshButton">Refresh</button>
</div>
它没有用。工具栏中的按钮呈现为标准HTML按钮而不是Dojo小部件。我做错了什么?
答案 0 :(得分:1)
我认为您错过了在模板containerNode div中设置dojo类型data-dojo-type='dijit/Toolbar'
。
您必须设置:
<div data-dojo-type='dijit/Toolbar' class="dijit" role="toolbar" tabIndex="${tabIndex}" data-dojo-attach-point="containerNode">
require(["dijit/Toolbar", "dijit/form/Button","dojo/parser", "dojo/domReady!"], function(Toolbar, Button, Parser) {
Parser.parse();
});
&#13;
<script src="//ajax.googleapis.com/ajax/libs/dojo/1.10.4/dojo/dojo.js"></script>
<link href="//ajax.googleapis.com/ajax/libs/dojo/1.10.0/dijit/themes/claro/claro.css" rel="stylesheet"/>
<div class="claro">
<div class="dijit" data-dojo-type='dijit/Toolbar' role="toolbar" tabIndex="${tabIndex}" data-dojo-attach-point="containerNode">
<button data-dojo-type="dijit/form/Button" data-dojo-attach-point="addButton">Add</button>
<button data-dojo-type="dijit/form/Button" data-dojo-attach-point="editButton">Edit</button>
<button data-dojo-type="dijit/form/Button" data-dojo-attach-point="removeButton">Remove</button>
<button data-dojo-type="dijit/form/Button" data-dojo-attach-point="refreshButton">Refresh</button>
</div>
</div>
&#13;