简体   繁体   English

即兴状态之间传递变量

[英]Passing Variables Between States in Impromptu

I'm currently using Impromptu for a form process on my site. 我目前在网站上使用Impromptu进行表单处理。 However, I'm having trouble with passing variable information between the different states. 但是,我无法在不同状态之间传递变量信息。 I'm not entirely sure if it's even possible. 我不确定是否有可能。 But what I would like for it to do is pull the variable information from the first state and display it in the second state's input box. 但是我想做的是从第一个状态提取变量信息,并在第二个状态的输入框中显示它。 Can this be done? 能做到吗?

Test code: 测试代码:

<script>

function stateAttempt(id){

    var displayDrop;

    var txt = '<div class="field"><label for="dropDownValueName">Drop:</label>'+
    '<select name="dropDownValueName">'+
    '<option value="DropDownValue">Drop Down Option</option>'+
    '</select>'+
    '</div>';

    var txtTwo = '<div class="field"><label for="address">Value:</label> <input type="text" id="address" name="address" value="'+ displayDrop +'" /></div>';

var statesdemo = {
    state0: {
        title: 'State One',
        html: txt,
        buttons: { Cancel:false, Next: 1 },
        submit:function(e,v,m,f){           
            if(v){  
                flag = true;
                if (flag == true) {

                    console.log(f);

                     window.displayDrop = f.dropDownValueName; 

                    e.preventDefault();
                    $.prompt.goToState('state1');

                } else { return false; }

            } else {                
                $.prompt.close();
            }
        }
    },
    state1: {
        title: 'State Two',
        html: txtTwo,
        buttons: { Cancel: 1, Back: -1 },
        submit:function(e,v,m,f){           
            if(v){  
                if (flag == true) {

                    console.log(f);

                    e.preventDefault();
                    if(v==1) $.prompt.close();
                    if(v==-1) $.prompt.goToState('state0');

                } else { return false; }

            } else {                
                $.prompt.close();
            }
        }
    },
};

$.prompt(statesdemo);
}

</script>

<a href="#" onclick="stateAttempt();">Display Prompt</a>

Geez, I've been working on this for hours and found adding this just before "$.prompt.goToState('state1');" 哎呀,我已经工作了好几个小时了,发现在“ $ .prompt.goToState('state1');”之前添加了它。 works: 作品:

jQuery.prompt.getStateContent('state1').find('#address').val(f.dropDownValueName);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM