Как использовать переменную Dialog, созданную в другом файле JS в файле Current JS в наборе инструментов dojo - PullRequest
0 голосов
/ 08 февраля 2019

Я создал диалог в файле AddButtonEntryPoint.js и хочу получить доступ к этой переменной в файле Form.js, чтобы скрыть диалоговое окно после нажатия кнопки «Отправить». Итак, как я могу позвонить.

Вот кодкоторый я написал

AddButtonEntryPoint.js

       var w = new Form({});

        var d = new Dialog({
            id: 'FormDialog',
            title: "Bridge Form",
            style: "width: 270px; height: 270px;",
            content: w,
            onHide: function() {
                // To prevent destroying the dialog before the animation ends
                setTimeout(lang.hitch(this, 'destroyRecursive'), 0);
            }
        });
            d.show();
        };          

Form.js

return declare( "mypackage.MyForm", Form, {
    repotextbox: new TextBox({
        name: "text",
        placeHolder: "Enter text here."
    } , dojo.doc.createElement('input')),

    DFMtextbox: new TextBox({
        name: "text",
        placeHolder: "Enter text here."
    } , dojo.doc.createElement('input')),

    submitButton: new Button({
        type: "submit",
        label: "Submit"
    }),

    constructor: function(args) {
        declare.safeMixin(this, args);
    },

    onSubmit: function() { 
        var repositoryID = this.repotextbox.get('value');
        xhr("https://samples.openweathermap.org/data/2.5/weather?q={repositoryID}",{ 
            // The URL of the request 
           method: "GET", 
            handleAs: "json", 
           }).then(
              function(data){ 

                alert(data.success + " " + JSON.stringify(data)); 
              }, 
              function(err){ 
              alert( "Your message could not be sent, please try again."); 
              });
    },    
});

});

В файле form.js, под функцией onSubmit я должен скрыть диалог, созданный в AddButtonEntryPoint.js, когда пользователь нажимает кнопку Отправить.

1 Ответ

0 голосов
/ 12 февраля 2019

В Form.js вы должны добавить свойство, которое будет ссылаться на экземпляр Dialog

return declare( "mypackage.MyForm", Form, {
    myDialog: null, 
    // etc
}

Затем в AddButtonEntryPoint вы можете установить это свойство при инициализации w, если вы установите его после:

        var d = new Dialog({
            id: 'FormDialog',
            title: "Bridge Form",
            style: "width: 270px; height: 270px;",
            content: w,
            onHide: function() {
                // To prevent destroying the dialog before the animation ends
                setTimeout(lang.hitch(this, 'destroyRecursive'), 0);
            }
        });

        var w = new Form({
            myDialog: d
        });

или вы можете оставить его как есть и вызвать w.set("myDialog", d); позже - но в этом случае любой код в postCreate, который требует диалоговое окно, не будет запускаться.

Надеюсь, это поможет!

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...