X-Editable:如何添加参数

时间:2016-06-30 13:13:41

标签: x-editable

我当前(非常非常简单)的脚本如下:

    <script type="text/javascript">
        $(document).ready(function () {
            $('.edit').editable();
        });
    </script>

我的HTML如下:

<span class="edit editable editable-pre-wrapped editable-click" data-title="Target Value">£135,000</span>

我的问题是如何为此添加更多参数,以便处理脚本选择它们?假设我想添加:

data-title="cows"

我尝试了以下哪些功能无效但将$(this).data("data-title")更改为数字,它可以正常工作。任何想法?

<script type="text/javascript">
            $(document).ready(function () {
                $('.edit').editable({
                    type: 'textarea',
                    pk: 1,
                    url: '/poo',
                    ajaxOptions: {
                        type: 'POST'
                    },
                    params: {
                        titleDesc: $(this).data("data-title"),
                    }
                });
            });
        </script>

1 个答案:

答案 0 :(得分:0)

您可以使用url方法来实现。

    <a href="#" class="comments" data-type="textarea" data-siteid="123456789" data-commentdate="2018-12-31"></a>

    $('.comments').editable({
        title: 'Enter comments',
        placeholder: 'Enter comments',
        type: 'textarea',
        rows: 2,
        cols: 50,
        validate: function (value) {
            if ($.trim(value) == '') {
                return 'This field is required';
            }
        },
        ajaxOptions: {
            type: 'post'

        },
        url: function (params) {
            var comment = params.value;
            var elem = $(this);
            var siteId = elem.data('siteid');
            var commentDate = elem.data('commentdate');

            $.ajax({
                url: '/GlobalBudget/SaveComment',
                type: 'POST',
                data: {
                    siteId: siteId,
                    comment: comment,
                    commentDate: commentDate
                },
                success: function (response) {
                    if (response.success) {
                        toastr.success(response.message);
                    } else {
                        toastr.error(response.message);
                    }
                },
                error: function (response) {
                    toastr.error("Could not save your comment. Please try again later.");
                }
            });
        }
    });