简体   繁体   English

将先前的可编辑值发送到服务器

[英]Send previous xeditable value to the server

I am using https://vitalets.github.io/x-editable/docs.html as a select element. 我正在使用https://vitalets.github.io/x-editable/docs.html作为选择元素。 In addition to sending the new value to the server (ie s, p), I would like to also send the previous value (ie b). 除了将新值发送到服务器(即s,p)之外,我还要发送先前的值(即b)。 The following script will do so initially, but will only send the original value (ie p) even if it is changed multiple times and the new previous value is no longer p. 下面的脚本最初会这样做,但是即使多次更改并且新的先前值不再是p,也只会发送原始值(即p)。

<a href="javascript:void(0)" class="doc-type" data-value="b"></a>

$('.doc-type').editable({
    type: 'select',
    placement: 'right',
    title: 'Document Type',
    source: [{value:'b',text:'Buy'},{value:'s',text:'Sell'},{value:'p',text:'Project'}],
    //params: {task:'saveDocType',controller:'portal',cid:ayb.component.id,CSRF:ayb.CSRF,doc_id:function(){console.log(this);}},
    params: function(params) {
        //originally params contain pk, name and value
        delete(params.name);
        params.task = 'saveDocType';
        params.controller = 'portal';
        params.cid = ayb.component.id;
        params.CSRF = ayb.CSRF;
        params.doc_id=$(this).parent().parent().data('id');
        params.v_old=$(this).data('value');
        return params;
    },
    url: 'index.php',
    pk: function(){return $('#id').val();},
    error: function (response, newValue) {
        //Unlike other validation, save function to return non 200 header.
        return response.responseText;
    },
});

I expect there is a better way, but one option is to save the newValue in the success callback. 我希望有更好的方法,但是一种选择是将newValue保存在成功回调中。

$('.doc-type').editable({
    type: 'select',
    source: [{value:'b',text:'Buy'},{value:'s',text:'Sell'},{value:'p',text:'Project'}],
    params: function(params) {
        //originally params contain pk, name and value
        params.v_old=$(this).data('value');
        return params;
    },
    url: 'index.php',
    pk: function(){return $('#id').val();},
    success: function(response, newValue) {
        $(this).data('value',newValue)
    }
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM