javascript 在 x-editable 中发送自定义参数
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19373848/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Send custom parameter in x-editable
提问by Abs
I am using x-editable to populate select list in popup. Now I want to send my key to server, my code is something like that
我正在使用 x-editable 在弹出窗口中填充选择列表。现在我想将我的密钥发送到服务器,我的代码是这样的
<a href="#" id="status" data-type="select" data-pk="1" data-url="${g.createLink(controller: 'someController', action: 'someAction')}" data-title="Select CV" class="btn btn-primary">
<image src="${resource(dir: 'images/template', file: 'logo11.png')}"/> ${session.someList?.size()} CV(s) Created
</a>
<script>
$(function () {
$('#status').editable({
value: 1,
source: [
<g:each in="${session.someList}" var="xyz" status="idx">
{value: ${xyz?.id}, text: "${xyz.title}", srsSelected: ${xyz.id}, updateXyz: "updateXyz"},
</g:each>
]
});
});
</script>
I want to send my srsSelected key to server, I did google but not getting the point...
我想将我的 srsSelected 密钥发送到服务器,我做了谷歌但没有明白这一点......
Edit:
编辑:
Now I am able to send my key to server(after long research) using
现在我可以将我的密钥发送到服务器(经过长时间的研究)使用
params: function (params) { //params already contain `name`, `value` and `pk`
var data = {};
data['cvSelected'] = params.pk;
return data;
}
therefore my updated code is:
因此我更新的代码是:
<a href="#" id="status" data-type="select" data-pk="1" data-url="${g.createLink(controller: 'someController', action: 'someAction')}" data-title="Select CV" class="btn btn-primary">
<image src="${resource(dir: 'images/template', file: 'logo11.png')}"/>
${session.someList?.size()} CV(s) Created
</a>
<script>
$(function () {
$('#status').editable({
value: 1,
source: [
<g:each in="${session.someList}" var="xyz" status="idx">
{value: ${xyz?.id}, text: "${xyz.title}", srsSelected: ${xyz.id}, updateXyz: "updateXyz"},
</g:each>
],
params: function (params) { //params already contain `name`, `value` and `pk`
var data = {};
data['srsSelected'] = params.pk;
return data;
}
});
});
</script>
I am able to send value of pk
in srsSelected
key but this time I need to set value of srsSelected
dynamically.
我可以发送pk
insrsSelected
键的值,但这次我需要srsSelected
动态设置值。
回答by Abs
And Now I found the method to set the value of srsSelected
dynamically as
现在我找到了srsSelected
动态设置值的方法
params: function (params) {
params.srsSelected = params.pk
return params;
}
and setting the value of data-pk
attribute in anchor tag dynamic, we can get srsSelected
at controller action.
并data-pk
在锚标签动态中设置属性的值,我们可以srsSelected
在控制器动作中获得。