开发者

jQuery UI Nested Sortable, sending additional data

开发者 https://www.devze.com 2023-02-09 19:45 出处:网络
Another question relating to jQuery UI Nested Sortable 1.2.1. We call the function like this: $(document).ready(function(){

Another question relating to jQuery UI Nested Sortable 1.2.1.

We call the function like this:

$(document).ready(function(){
$('ol.sortable').nestedSortable({
disableNesting: 'no-nest',
forcePlaceholderSize: true,
handle: 'div',
items: 'li',
opacity: .6,
placeholder: 'placeholder',
tabSize: 25,
tolerance: 'pointer',
toleranceElement: '> div'
});

I was thinking how can I send additional information through this, like:

$(document).ready(function(){
$('ol.sortable').nestedSortable({
disableNesting: 'no-nest',
forcePlaceholderSize: true,
handle: 'div',
items: 'li',
left_val: '<?=$lft?>',
root_id: '<?=$id?>', 
opacity: .6,
placeholder: 'placeholder',
tabSize: 25,
tolerance: 'pointer',
toleranceElement: '> div'
});

Idea is to use the three variables, left_val, root_id and holder in the following fashion in the toArray function.

var left = this.left_val;
var root_id = this.root_id;

Th开发者_如何转开发is is not working, of course. Values are coming out as NaN, NaN and undefined.

Doing an alert(left+' '+root_id); just below var left = this.left_val; var root_id = this.root_id; is giving me an alert stating undefined undefined

The options of options are coming from the parent plugin jQuery UI.

Just wondering if anyone can throw light to this, please.

EDIT:

I tried a different trick. I tried to send the left and root_id values through <ol class="sortable" title="<?=$lft?>|<?=$id?>"> and then in the js page, I tried

if ($(this).parent().attr('class') == 'sortable') {
var idArray = $(this).parent().attr('title').split("|");
} 

But I'm getting $(this).parent().attr('class') as undefined on alert.


Have you looked at JQuery.data() ? This will let you store arbitrary data in key/value pairs with a element. JQuery Data() Documentation

Here is some more documentation Link


This is finally solved with:

var idArray =$(this.element).closest("ol.sortable").attr('title').split("|");
0

精彩评论

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