Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/425.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 用于ajax调用内容的dojo_Javascript_Ajax_Dojo - Fatal编程技术网

Javascript 用于ajax调用内容的dojo

Javascript 用于ajax调用内容的dojo,javascript,ajax,dojo,Javascript,Ajax,Dojo,本案: 我使用dojo请求一个页面并将其加载到一个div(视图)中 问题是: 加载到表单中的内容包含dojo表单和相关对象、文本框等。。。如何控制这些小部件?我相信我目前处理这个问题的方式是草率的,可以更精细一些 代码中的注释有助于解释我遇到的问题。请让我知道你的想法 function (parser, domAttr, util, ready, dom, on, request, domStyle, registry, TextBox) { //This prepares the doc ma

本案: 我使用dojo请求一个页面并将其加载到一个div(视图)中

问题是: 加载到表单中的内容包含dojo表单和相关对象、文本框等。。。如何控制这些小部件?我相信我目前处理这个问题的方式是草率的,可以更精细一些

代码中的注释有助于解释我遇到的问题。请让我知道你的想法

function (parser, domAttr, util, ready, dom, on, request, domStyle, registry, TextBox) {
//This prepares the doc main html page We are looking for a click of a menu option to load in thats pages pages content     

        ready(function () {     
            //Look for click of menu option            
            on(dom.byId('steps'), "a:click", function(e) {
                event.preventDefault();

                //Get the div we are going to load the page into
                var view = domAttr.get(this, "data-view");                
                // function that loads the page contents
                load_page(view);  
            });
        });    

        function load_page(view) {
            //First I see if this page already has widgets and destroy them
            //We do this so users can toggle between menu items
            // If we do not we get id already registered
            var widgets = dojo.query("[widgetId]", dom.byId('apply-view')).map(dijit.byNode);
            dojo.forEach(widgets, function(w){ 
                w.destroyRecursive();
            });


            //get the html page we are going to user for the menu item
            request.post("/apply_steps/"+view, {
                data: {
                    id: 2
                }
            }).then(
            function(response){
                //Add the content and parse the page   
                var parentNode = dom.byId('apply-view');
                parentNode.innerHTML = response;
                parser.parse(parentNode);

                //This is where it is sloppy
                //What I would prefer is to load a new js file the controlls the content that was just loaded
                //What happens now is I create a traffic director to tell the code what main function to use
                controller_director(view);
            },
            function(error){
                util.myAlert(0, 'Page not found', 'system-alert');
            });
        }   

        function controller_director(view) {
            //based on the view switch the function
            switch(view) {
                case 'screening_questions':
                    screening_questions();
                    break;
            }

        }  

        function screening_questions() {
            //Now we are controlling the page and its widgets
           // How would I get this info into a seperate js file that i would load along with the ajax call??
            ready(function () {         

                on(dom.byId('loginForm'), "submit", function(e) {
                    event.preventDefault();
                    var formLogin = registry.byId('loginForm');
                    authenticate();                   
                });
            }); 

            this.authenticate = function() {
                var formLogin = registry.byId('loginForm');
                if (formLogin.validate()) return;
            } 
        }    
});

我建议您将表单制作成一个定制的模板小部件,并在表单小部件中编写事件处理程序和表单验证逻辑。在本例中,您所要做的就是在页面中使用声明性引用ajax并调用dojo解析器。谢谢你的建议。我要试一试。