Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

});
like image 477
user1032531 Avatar asked Jan 09 '23 11:01

user1032531


1 Answers

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.

like image 98
tdbts Avatar answered Jan 11 '23 00:01

tdbts