jquery 验证器中的 GetOrgChart 值未更新
GetOrgChart value not updating in jquery validator
我正在尝试更新 GetOrgChart 中的元素,为此我正在执行以下操作
Html
<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>
JavaScript
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"}]
});
现在只需单击图表元素然后提交表单,您就会看到
首次单击
后 validate
函数的 args.id
值未更改
你的问题好像是变量的范围"args".
它在 clickEvent
上调用的匿名函数中变量 "born",它仅存在于该事件中。
submitHandler
是由另一个内部函数管理的处理程序;所以它在clickEvent的范围之外。
所以解决方案是声明(在两个函数之外都有一个具有页面范围的变量)。
然后,在单击事件上,将其分配给 args
的 id
。
这样你也可以在提交事件中使用它。
简而言之(我用我添加的“//---”行评论):
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"}]
});
希望对您有所帮助...:)
我正在尝试更新 GetOrgChart 中的元素,为此我正在执行以下操作
Html
<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>
JavaScript
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"}]
});
现在只需单击图表元素然后提交表单,您就会看到
首次单击
后validate
函数的 args.id
值未更改
你的问题好像是变量的范围"args".
它在 clickEvent
上调用的匿名函数中变量 "born",它仅存在于该事件中。
submitHandler
是由另一个内部函数管理的处理程序;所以它在clickEvent的范围之外。
所以解决方案是声明(在两个函数之外都有一个具有页面范围的变量)。
然后,在单击事件上,将其分配给 args
的 id
。
这样你也可以在提交事件中使用它。
简而言之(我用我添加的“//---”行评论):
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"}]
});
希望对您有所帮助...:)