【发布时间】:2017-04-04 18:22:56
【问题描述】:
我有一个 X-editable 元素从 data-pk 属性获取字段。
<button class='edit' data-pk='field|value'>My Button</button>
我正在使用另一个下拉菜单动态更新此按钮。这样 data-pk 就会更新到我从下拉列表中选择的任何字段。
DOM 按预期更新。
但是,当 X-editable 触发请求时,它是旧的第一个启动的 data-pk 值。 在发送到服务器之前,如何让它读取当前值?
X 可编辑代码是...
$('.edit').editable({
url:'user/edit',
// Need something here to retrieve the real current value of data-pk.
// not initiated value
success:function(response,value){
// Do success stuff.
}
});
我试过了……
$('.edit').editable({
url:'user/edit',
pk:$(this).attr('data-pk'),
success:function(response,value){
}
});
但是没用,也试过了……
$('.edit').editable({
url:'user/edit',
params:function(params){
var data={};
// Need to get this instance, and fetch the current data-pk
// So I can set it in this data, but I have no idea how to get it.
// params.pk just gives me the old value. I need to get the new value
return data;
},
success:function(response,value){
// Do success stuff.
}
});
【问题讨论】:
-
我在同一条船上。你有没有得到解决方案?
-
是的,我确实找到了解决方案....像这样的参数:function(params) { params.pk = $(this).attr('data-pk');返回参数; },
标签: jquery x-editable