jquery - $(this) not working x-editable -


i'm trying set dynamic retrieve of pk , selector not working, here code:

#html file <div id="{{task.id}}">                 <h3>                     <a href="#" id="task">{{ task.task }}</a>                 </h3> ... </div>  #js file $("#task").editable({     type: 'text',     **pk:  $(this).closest('div').attr('id'),**     url: '/update_task/' + pk + '/',     title: 'enter task',  }); 

this 1 not working, if write:

pk:  $("#task").closest('div').attr('id') 

will work, not convenient me.

thank in advance :)

this refers options object, , not jquery object. if have one-off field want extract primary key send server, do:

var $task = $("#task"); $task.editable({     type: 'text',     pk:  $task.attr("id"),     url: '/update_task/' + pk + '/',     title: 'enter task', }); 

if using more generic selector, such .somediv , want pk each individual one, can use params option callback, allows append/overwrite data sent, depending on whether pass object or function (function overwrites, see docs):

$(".somediv").editable({     type: 'text',     pk:  0,      // hooray, params takes callback     // can right context     params: function (params) {         var data = {};         data.pk = $(this).closest("div").attr("id"),         data.makesure = "you know overwrite original params object";         data.soput = "everything need before returning";         return data;     },     url: '/update_task/' + pk + '/',     title: 'enter task' }); 

p.s. pk seems accept function too, guess can this, i'm in no position test right now:

$("#task").editable({     type: 'text',     pk:  function () {         return $(this).closest("div").attr("id");     },     url: '/update_task/' + pk + '/',     title: 'enter task' }); 

Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

c# - must be a non-abstract type with a public parameterless constructor in redis -

ajax - PHP/JSON Login script (Twitter style) not setting sessions -