如何重写的X编辑Ajax响应值? [英] How to override x-editable ajax response value?
问题描述
我使用的X编辑做在线编辑。当我更新通过AJAX和X编辑获得响应的价值,我发现很难覆盖包含新的x值可编辑的DIV。
I am using x-editable to do inline editing. When I update the value via ajax and x-editable to get the response, I am finding it very difficult to override the div that contains the new x-editable value.
例如,我的X-编辑链接看起来是这样的:
For example, my x-editable link looks like this:
<a href="#" id="freight">$100</a>
输入我的弹出窗口的X编辑提供再输入值编辑300.00
I enter my edit in the pop-up that x-editable provides then enter the value 300.00
当我做我的编辑,我的步骤如下:
When I do my edits, I proceed as follows:
$('#freight').editable({
validate: function(value) {
if($.trim(value) == '') return 'This value is required.';
},
type: 'text',
url: '{{ path('update_purchase_order_ajax') }}',
pk: {{ purchaseOrder.id }},
title: 'Enter Freight Value',
ajaxOptions: {
dataType: 'json'
},
success: function(response, newValue) {
// Update the purchase order amounts...
$('#freight').html('$' + newValue);
}
});
当的x可编辑完成时,显示在网页上的值是现在300.00(不$美元符号)。正如你可以在我的jQuery code见,我试图重写值x编辑与$把页面上('#货运)HTML('$'+为newValue);
When x-editable is finished, the value that shows up on the page is now 300.00 (without the $ dollar sign). As you can see in my jquery code, I am trying to override the value x-editable is putting on the page with $('#freight').html('$' + newValue);
出于某种原因,这是行不通的。我想$ 300.00展现出来,而不是300.00。
For some reason this is not working. I want $300.00 to show up, not 300.00.
推荐答案
您需要做的是prevent的显示,从覆盖你的<$ C $
方法C>成功方法。
What you need to do is prevent the display
method from overwriting your success
method.
display: function(value, response) {
return false; //disable this method
},
success: function(response, newValue) {
$(this).html('$' + newValue);
}
在服务器端,你的JSON应该是这样的, {为newValue:其中;价值&GT;}
On the server side, your JSON should be like this, {newValue : <value>}
这篇关于如何重写的X编辑Ajax响应值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!