gpt4 book ai didi

javascript - dataEvents 和 .change() 方法在 jqgrid/jquery 中不起作用

转载 作者:行者123 更新时间:2023-11-28 10:55:43 29 4
gpt4 key购买 nike

我有一个 jqgrid,有以下两列:OwnerNotifyUsersNotifyUser 取决于 Owner 列的值。就像国家 -> 州 -> 城市。

 {name:'owner',index:'owner',width:80,hidden:false,search:false,align:'center',
edittype:'select',editable:true},

{name:'notifyUsers',index:'notifyUsers',width:100,hidden:false,search:false,align:'center',
edittype:'select',editable:true,editoptions:{ value:'${notifiedUserList}', multiple: true}},

我正在做表单编辑。当我们选择任何行时,我有下面的代码来填充这两个 SelectBox。

 ondblClickRow: function(rowid) {               
$("#searchcriteraigrid").setColProp('owner', {editoptions:{dataUrl:'getUserList.html?critId=' + rowid}});
$("#searchcriteraigrid").setColProp('notifyUsers', {editoptions:{dataUrl:'getNotifiedUSerList.html?critId=' + rowid, multiple: true}});
)};

到目前为止没有问题。

但我需要根据 Owner 下拉列表的值填充 NotifyUsers 下拉列表。

我尝试了两种方法,例如在所有者列中使用以下代码。

editoptions:{                           
dataEvents: [
{
type: 'change',
fn: function(e) {
modifyNotifyUsers(e);
}
}
]
},

并修改NotifyUsers(e)某处写为

function modifyNotifyUsers(e){
var userId = $(e.target).val();
$.ajax({
url:"getNotifiedUsersOnOwner.html?userId="+userId,
type: "get",
success:function(newOptions){
var form = $(e.target).closest("form.FormGrid");
$("select#notifyUsers.FormElement",form[0]).html(newOptions);
}
});
}

这种方法不起作用,因为我认为,我在 Owner 列的 editoptions 中没有使用 value 属性。我尝试也在 editopions 中使用 dataUrl 但我的 url 是动态的,这就是为什么我必须将 dataUrlondblClickRow() 一起使用>

我尝试在 Owner 下拉列表的更改上调用简单的 jquery 方法,如下所示。

$('#owner').change(function(){
$('#searchcriteraigrid').setColProp('notifyUsers',{
editoptions:{
dataUrl:'getNotifiedUsersOnOwner.html?crit'+$('#criteriaId').val()
}
});

但是这个方法调用也没有发生。讽刺的是,当我将页面保存为简单的 HTML 并在浏览器中打开该 HTML 时,就会发生此方法调用。我可以通过在方法中添加一些警报来查看。

您能否帮助我以任何方式使其正常工作,或者建议我做错了什么以及哪里做错了。

最佳答案

我使用下面的代码解决了这个问题。我不知道 .change() 不起作用但 .live('change') 起作用的原因是什么。后来我进行了 ajx 调用并动态设置我的选择框。

$('#owner').live('change', function() {
var val = $('#owner').val();
$.ajax({
type: "post",
url: 'getNotifiedUsersOnOwner.html?userId='+val,
success: function(response) {
$("#notifyUsers").html(response);
}
});
});

如果您有更好的方法,请提供建议。谢谢

关于javascript - dataEvents 和 .change() 方法在 jqgrid/jquery 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23928262/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com