dojo:如何克隆小部件?

发布于 2024-12-15 02:09:38 字数 221 浏览 2 评论 0原文

如何克隆 Dojo 表单 (dijit.form.Form) 及其子部件?理想情况下,我也想更改克隆小部件的 ID。我也有兴趣克隆可能附加到小部件的任何事件。

我玩了一下 dojo.clone 但这只适用于 DOM 对象。

谢谢

How do I go about cloning a Dojo form (dijit.form.Form) with its child widgets? Ideally, i'd like to change the Id's of the clone widgets as well. I also would be interested in cloning any events that might be attached to the widgets.

I played a bit with dojo.clone but that only works for DOM objects.

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

岁月静好 2024-12-22 02:09:38

假设继承确实是您所需要的,那么我只需制作一个新的小部件。假设您正在使用异步加载器和 Dojo 1.7。我会做类似的事情:

define([
    'dojo',
    'module',
    'dijit/form/Form',
    'dijit/form/TextBox',
    'dijit/_TemplatedMixin',
    'dijit/_WidgetsInTemplatedMixin'
], function (dojo, module, Form, TextBox, _TemplatedMixin, _WidgetsInTemplatedMixin) {
    // I have a wrapper for declare that handles this, but...
    return dojo.declare(module.id.replace(/\//g, '.'), [Form, _TemplatedMixin, _WidgetsInTemplatedMixin], {

        widgetsInTemplate: true,

        // Make a template, I usually use a separate file.
        templateString: '<form data-dojo-type="dijit.form.Form">' +
                             '<input data-dojo-type="dijit.form.TextBox" />' +
                        '</form>'

        postCreate: function () {
            this.inherited(arguments);
            // Attach your specialized events.
        }
    });
});

如果您使用同步加载器,那么您将需要 dojo.declare

dojo.provide('mynamespace.CustomForm');

// Do this for all child widgets and anything else you use.
dojo.require('dijit.form.Form'); 
dojo.require('dijit._Templated');
dojo.require('dijit.form.TextBox');

dojo.declare('mynamespace.CustomForm', [dijit.form.Form, dijit._Templated], {

        widgetsInTemplate: true,

        // Make a template, I usually use a separate file.
        templateString: '<form dojoType="dijit.form.Form">' +
                             '<input dojoType="dijit.form.TextBox" />' +
                        '</form>'

        postCreate: function () {
            this.inherited(arguments);
            // Attach your specialized events.
        }
    });
});

然后您的模块将可通过 var container = someElement; 来使用。新的path.to.File({},容器);。或者您可以在标记中声明该小部件。请告诉我是否可以使其更具体或适用于不同版本的 Dojo。

Assuming inheritance is really what you need, then I'd just make a new widget. Assuming you are using the async loader and Dojo 1.7. I'd do something like:

define([
    'dojo',
    'module',
    'dijit/form/Form',
    'dijit/form/TextBox',
    'dijit/_TemplatedMixin',
    'dijit/_WidgetsInTemplatedMixin'
], function (dojo, module, Form, TextBox, _TemplatedMixin, _WidgetsInTemplatedMixin) {
    // I have a wrapper for declare that handles this, but...
    return dojo.declare(module.id.replace(/\//g, '.'), [Form, _TemplatedMixin, _WidgetsInTemplatedMixin], {

        widgetsInTemplate: true,

        // Make a template, I usually use a separate file.
        templateString: '<form data-dojo-type="dijit.form.Form">' +
                             '<input data-dojo-type="dijit.form.TextBox" />' +
                        '</form>'

        postCreate: function () {
            this.inherited(arguments);
            // Attach your specialized events.
        }
    });
});

If you're using the sync loader, then you'll want dojo.declare:

dojo.provide('mynamespace.CustomForm');

// Do this for all child widgets and anything else you use.
dojo.require('dijit.form.Form'); 
dojo.require('dijit._Templated');
dojo.require('dijit.form.TextBox');

dojo.declare('mynamespace.CustomForm', [dijit.form.Form, dijit._Templated], {

        widgetsInTemplate: true,

        // Make a template, I usually use a separate file.
        templateString: '<form dojoType="dijit.form.Form">' +
                             '<input dojoType="dijit.form.TextBox" />' +
                        '</form>'

        postCreate: function () {
            this.inherited(arguments);
            // Attach your specialized events.
        }
    });
});

Your module will then be available with var container = someElement; new path.to.File({}, container);. Or you could declare the widget in your markup. Let me know if I can make this more specific or apply to different versions of Dojo.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文