Search code examples
javascriptjqueryx-editable

Add parameter to x-editable params


x-editable has the option() method which is used to set a new option. params is one of the options and happens to be an object, and instead of replacing params with a new object, I just want to add a property to the existing params object. Below is my attempt, but I am inadvertently overwriting params and not adding a new property as desired.

http://jsfiddle.net/fo1susa1/

$(function() {

    $('#name').editable({
        url: '/echo/json/',
        pk: 123,
        params:{a:1,b:2}
    })
    .on('shown', function(e, editable) {
        editable.option('params', {c:3});
    });

});

Solution

  • You can add a property to the existing params object like this:

    $(function() {
    
        $('#name').editable({
            url: '/echo/json/',
            pk: 123,
            params:{a:1,b:2}
        })
        .on('shown', function(e, editable) {
            editable.options.params.c = 3;
            // editable.options.params is now {a: 1, b: 2, c: 3}
        });
    
    });
    

    Hope this helps.