开发者

Question about using a jQuery plugin over a series of matched elements

开发者 https://www.devze.com 2023-03-23 11:16 出处:网络
I am using jQuery In Place Editor to make allow in place editing of a few text elements in my page. $(\".entry_name\").editInPlace({

I am using jQuery In Place Editor to make allow in place editing of a few text elements in my page.

$(".entry_name").editInPlace({
    url: "/entries/change_name",
    params: "entry_id=XXX"
});

The params option allows me to send some parameters along with the post request. I need to specify a different entry_id for each element that matches the .entry_name selector. An example of a matched element is:

<span id="entry_nam开发者_Go百科e_24" class="entry_name" data-entry_id="24">example</span>

So in this example, the params option should be entry_id=24

How can I do this?


You need to call editInPlace on each element separately:

$(".entry_name").each(function(){
    $(this).editInPlace({
        url: "/entries/change_name",
        params: "entry_id="+$(this).data('entry_id');
    });
});


this will do the trick-

$(".entry_name").editInPlace({
    url: "/entries/change_name",
    params: "entry_id"+this.data('entry_id')
});


You need to use

$(".entry_name").each(function(){
    var currentID = $(this).data('entry_id');

    $(this).editInPlace({
        url: "/entries/change_name",
        params: "entry_id=" + currentID 
    });
});

But keep in mind that the plugin (according to the Usage section) already passes the id of the element when submitting, but with another name element_id

Once the in-place editor form is submitted, it sends a POST request to the URL that is specified in the editor’s parameters along with three form fields:

  • original_html; the original text in the in-place editor container
  • update_value; the new value of the text from the in-place editor
  • element_id; the id attribute of the in-place editor

edit : sorry, missed that you are getting the entry_id and not the actual id (although you could extract it from the actual id)

0

精彩评论

暂无评论...
验证码 换一张
取 消