سؤال

I am using x-editable for in-line editing inside my web app. I would like to pass additional parameters to server, which I would like to read from data- attributes on trigger element. Here is my editable element:

<a href="#" data-url="save_url" data-pk="271" data-type="text" data-value="Value" class="editable" data-param="XXX">Value</a>

I would like to pass data-param attribute, but I don't know how to access trigger element. I tried via $(this).data('param'), but I get null... My full editable code:

$.fn.editable.defaults.mode = 'inline';
$('.editable').editable({
    params: { param: $(this).data('param') }
});

Calling $('.editable').data('param') doesn't come into account since I have many .editable elements present.

Thanks

هل كانت مفيدة؟

المحلول

I figured it out. I'm answering in case somebody needs to know:

$('.editable').editable({
    params: function(params) {
        // add additional params from data-attributes of trigger element
        params.param1 = $(this).editable().data('param');
        params.param2 = $(this).editable().data('nextparam');
        return params;
    }
)
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top