2

我想在 Qooxdoo 应用程序中有一些对话框,但我不知道如何在某些情况下定义它们。

在 Qooxdoo 演示中(它是小部件 - 窗口示例,函数 getModalWindow2),我看到可以像简单的 JS 函数一样定义窗口,返回它的小部件。有没有更好的方法在 Qooxdoo 中进行对话?

据我了解,我可以为对话框窗口定义类并为该类设置一些类属性。那么,如何在应用程序中添加一些表单复杂的对话框呢?

例如,它可能是服务器上的用户目录树。在用户按下“确定”按钮后,树的选定元素必须存储在对话框类的对象中,该对话框将关闭。

4

1 回答 1

1

现在我找到了我自己问题的答案(在关于 Qooxdoo的俄语博客中,我将在这里翻译答案)。

因此,主应用程序和对话框的单独文件中有单独的类。

在对话框中,我们正在添加qx.event.type.Data以通过此事件输出结果。

因此,例如,我们有一个名为“custom”的 Qooxdoo 应用程序,就像在文档中一样。

在 Application.js 中,我们将此代码用于类:

    // Adding dialog window
    this.__uiWindow = new custom.UserDialog();
    this.__uiWindow.moveTo(320, 30);
    this.__uiWindow.open();

    // Adding the listener for pressing "Ok"
    this.__uiWindow.addListener("changeUserData", function (e) {
        this.debug(e.getData());
    });

e.getData()正在提供结果信息。

然后我们必须为该类创建名为UserDialog.js的文件,其中包含事件和表单:

    qx.Class.define("custom.UserDialog", {
        extend: qx.ui.window.Window,
        events: {
            "changeUserData": "qx.event.type.Data"
        },
        construct: function () {
            this.base(arguments, this.tr("User info"));

            // Layout
            var layout = new qx.ui.layout.Basic();
            this.setLayout(layout);
            this.setModal(true);

            this.__form = new qx.ui.form.Form();

            // User id field
            var usrId = new qx.ui.form.TextField();
            this.__form.add(usrId, this.tr("ID"), null, "Id");

            // User password field
            var usrPassword = new qx.ui.form.PasswordField();
            usrPassword.setRequired(true);
            this.__form.add(usrPassword, this.tr("Password"), null, "Password");

            // Adding form controller and model
            var controller = new qx.data.controller.Form(null, this.__form);
            this.__model = controller.createModel();

            // Save button
            var okbutton = new qx.ui.form.Button(this.tr("Ok"));
            this.__form.addButton(okbutton);
            okbutton.addListener("execute", function () {
                if (this.__form.validate()) {
                    var usrData = qx.util.Serializer.toJson(this.__model);
                    this.fireDataEvent("changeUserData", usrData);
                    this.close();
                };
            }, this);

            // Cancel button
            var cancelbutton = new qx.ui.form.Button(this.tr("Cancel"));
            this.__form.addButton(cancelbutton);
            cancelbutton.addListener("execute", function () {
                this.close();
            }, this);

            var renderer = new qx.ui.form.renderer.Single(this.__form);
            this.add(renderer);
        }
    });
于 2011-09-15T13:07:17.937 回答