在jEditable中将父级ID作为参数发送

时间:2009-04-09 14:56:18

标签: jquery

鉴于

$(".foo").editable("script.php")

如何将.foo的父ID作为参数传递?我试过了

$(".foo").editable("script.php", { 

     submitdata: {

          parent_id: $(this).parent().attr('id')

                 }
     });

以及我能想到的每个变体,但看起来好像$(this)对象在这种情况下不起作用。

3 个答案:

答案 0 :(得分:15)

我在这里遇到了同样的问题,找到了以下解决方案:

$('.jeditable').each(function() {
   var $this = $(this);
   $this.editable('submit.jsp', {
      submitdata  : { parent_id : $this.parent().attr('id') }
   });
});

答案 1 :(得分:0)

你可以进行Ajax调用,这样你就可以传递所有内容(如果你正在寻找未来,也许你会添加一些功能......)。

示例:

$('.edit').editable(
    function(value, settings) {

        // prepare the data, add all parameters you want

        var data = "param1=value1" +
            "&param2=value2";

        var ret = "";

        // make the ajax call to do the work (not async)
        $.ajax({
            type: "POST",
            url: "page.php",
            data: data,
            async: false,
            success: function(msg) {

                if (msg.length != 0) {

                    // set the value to write in the element
                    ret = msg;

                }

            }

        });

        // return the element to save into the element
        return ret;

    }, {

        // set the jeditable setting
        cssclass: 'classname'
    }

);

我认为这种方法在处理每个案例时都更灵活。

答案 2 :(得分:-1)

我会这样做:

$(".foo").editable("script.php", { submitdata: { parent_id: $(".foo").parent().attr('id') } });

你的问题中也有一个拼写错误,你有$(。foo).editable()而不是$(“。foo”)。editable()。如果这也是您的实际代码,那可能是问题的根源。