acslater323
10-24-2007, 10:59 AM
I'm looping through every TBODY tag in my table and making it sortable with scriptaculous. The number of these TBODY tags is variable, as it is a database dump of categories and their items.
The problem i'm having is when i assign an onUpdate function to the Sortable. See below:
for(var i=0;i<categories.length;i++) {
var target = categories[i].id;
var handle = categories[i].id + "-handle";
Sortable.create(target,{tag: "tr", only: "sortable", constraint:"vertical",dragOnEmpty: true, cat: categories[i].id, onUpdate:
function() {
alert(this.cat); /*Returns "undefined" */
new Ajax.Updater('sortable-target','/ajax_scripts/item_order.php?productid=' + prodID + '&table=' + itemTable + '&sequence=' + Sortable.sequence('sortable-wrapper'), {
asynchronous:true,
onComplete: function() {
Effect.Highlight('sortable-wrapper');
}
});
}
});
}
The problem happens on this line:
Sortable.create(target,{tag: "tr", only: "sortable", constraint:"vertical",dragOnEmpty: true, cat: categories[i].id, onUpdate:
As you can see, I'm trying to pass the ID of the TBODY to the Sortable object so it is available to the onUpdate: function(), but within that function, the variable "this.cat" is undefined.
If I put "categories[i].id" in the function, it doesn't work either, because that function is not called within the loop, so it is unaware of "i"...
There must be a way to do this!
The problem i'm having is when i assign an onUpdate function to the Sortable. See below:
for(var i=0;i<categories.length;i++) {
var target = categories[i].id;
var handle = categories[i].id + "-handle";
Sortable.create(target,{tag: "tr", only: "sortable", constraint:"vertical",dragOnEmpty: true, cat: categories[i].id, onUpdate:
function() {
alert(this.cat); /*Returns "undefined" */
new Ajax.Updater('sortable-target','/ajax_scripts/item_order.php?productid=' + prodID + '&table=' + itemTable + '&sequence=' + Sortable.sequence('sortable-wrapper'), {
asynchronous:true,
onComplete: function() {
Effect.Highlight('sortable-wrapper');
}
});
}
});
}
The problem happens on this line:
Sortable.create(target,{tag: "tr", only: "sortable", constraint:"vertical",dragOnEmpty: true, cat: categories[i].id, onUpdate:
As you can see, I'm trying to pass the ID of the TBODY to the Sortable object so it is available to the onUpdate: function(), but within that function, the variable "this.cat" is undefined.
If I put "categories[i].id" in the function, it doesn't work either, because that function is not called within the loop, so it is unaware of "i"...
There must be a way to do this!