gpt4 book ai didi

javascript - 如何在 Dojo Toolkit 中为带有按钮的工具栏定义 Widget 类?

转载 作者:行者123 更新时间:2023-11-30 20:33:40 25 4
gpt4 key购买 nike

我将创建新类 - 带有标准操作按钮的工具栏(添加、编辑、删除、刷新)。我为此编写了简单的类:

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 小部件。我做错了什么?

最佳答案

我认为您只是错过了在模板 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();
});
<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>

关于javascript - 如何在 Dojo Toolkit 中为带有按钮的工具栏定义 Widget 类?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50063111/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com