GetOrgChart值未在jquery验证器中更新

时间:2015-10-09 07:54:31

标签: javascript jquery html jquery-validate getorgchart

我正在尝试更新GetOrgChart中的元素,并且我正在执行以下操作

HTML

Pro.find()
            .where({ 
                and:[
                    {status:{'!':'REMOVED'}}, 
                    {ex_date: {'>=': current_date}}
                ]})
            .populate('user_p')

的JavaScript

<form id="one">
    <input type="text" name="aaa">
    <input type="text" name="bbb">
    <input type="submit" name='submitform' value="submit">
</form>
<br> 
<div id="people"></div>

现在只需点击图表元素,然后提交表单即可看到

第一次点击后

var oneForm = $("#one"); $("#people").getOrgChart({ clickEvent: function( sender, args ) { alert('args.id value outside validate '+args.id); oneForm.show(); oneForm.validate({ // to add new area for team rules: { aaa: { required: true, minlength: 3 }, bbb: { required: true, minlength: 3 } }, submitHandler: function (form) { alert('args.id value inside validate '+args.id); oneForm.hide(); return false; } }) //return false; //if you want to cancel the event }, primaryColumns: ["Name", "Type"], linkType: "M", editable: false, zoomable: false, movable: true, gridView: true, dataSource: [ { id: 1, parentId: -1, Name: "Amber McKenzie", Title: "CEO", Address: "MyAddress"}, { id: 2, parentId: 1, Name: "Ava Field", Title: "CTO", Phone: "+359 888 888 888"}, { id: 3, parentId: 1, Name: "Evie Johnson", Title: "CFO", Car: "BMW"}] }); args.id功能的

JsFiddle

1 个答案:

答案 0 :(得分:2)

你的问题似乎是变量&#34; args&#34;。

的范围

变量&#34;天生&#34;在clickEvent上调用的匿名函数中,它只存在于该事件中。

submitHandler是由另一个内部函数管理的处理程序;所以它超出了clickEvent的范围。

所以解决方案是声明(在两个函数之外的一个带有页面范围的变量)。 然后,在点击事件中,将其id设为args。 通过这种方式,您也可以在提交事件中使用它。

简而言之(我评论了&#34; // ---&#34;我添加的行):

var oneForm = $("#one");
var globalArgsId; //--- Declare "global" variable
$("#people").getOrgChart({  
        clickEvent: function( sender, args ) {
            alert('args.id value outside validate '+args.id);
            globalArgsId = args.id; //--- Write value to global variable

            oneForm.show();
            oneForm.validate({
                 // to add new area for team
                 rules: {
                     aaa: {
                         required: true,
                         minlength: 3
                     },
                     bbb: {
                         required: true,
                         minlength: 3
                     }
                 },
                 submitHandler: function (form) {
                     alert('args.id value inside validate '+args.id);
                     alert('args.id value inside validate '+globalArgsId); //--- Access to global variable
                     oneForm.hide();
                     return false;
                 }
             })

            //return false; //if you want to cancel the event
        },

         primaryColumns: ["Name", "Type"],
         linkType: "M",
         editable: false,
         zoomable: false,
         movable: true,
         gridView: true,

        dataSource: [
            { id: 1, parentId: -1, Name: "Amber McKenzie", Title: "CEO", Address: "MyAddress"},
            { id: 2, parentId: 1, Name: "Ava Field", Title: "CTO", Phone: "+359 888 888 888"},
            { id: 3, parentId: 1, Name: "Evie Johnson", Title: "CFO", Car: "BMW"}]
    });

希望它有帮助...:)