Add parameter to x-editable parameters

x-editable has a method option()that is used to set a new option. paramsis one of the parameters and it turns out to be an object, and instead of replacing it paramswith a new object, I just want to add a property to an existing object params. The following is my attempt, but I inadvertently overwrite paramsand do not add a new property as I wish.

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});
    });

});
+4
source share
1 answer

You can add a property to an existing params object as follows:

$(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.

+7
source

All Articles