jquery nestable does not update
I'm using jquery nestable to create a list of academic programs a prospective student might be interested in. 16 programs pulled from mysql and listed like this:
<ol class="dd-list">
if(mysqli_num_rows($result)) {
$order = array();
while($item = mysqli_fetch_assoc($result)) {
echo '<li class="dd-item" data-id="'.$item['id'].'"><div class="dd-handle">',$item['program'],'</div></li>';
}
</ol>
} else {
<p>Sorry! There are no items in the system.</p>
}
No issue there. I have a second container to place the programs in:
<div class="dd" id="nestable2">
<h4>Place programs below in order of preference</h4>
<ol class="dd-list dd-placeholder">
<li class="dd-item" data-id="17">
<div class="dd-handle">Health Sciences Advisor</div>
</li>
</ol>
</div>
And the original list and the output to the second container are output as serialized json data in textareas like this:
Serialised Output (per list)
<textarea id="nestable-output"></textarea>
<textarea id="nestable2-output" name="nestable2-output"></textarea>
Again no real issue. The textareas will be changed to hidden inputs later.Except that sometimes when i drag a list item from the left column to the right the value doesn't update. here is a link to the jquery.nestable.js
and here is the script in the form:
$(document).ready(function()
{
var updateOutput = function(e)
{
var list = e.length ? e : $(e.target),
output = list.data('output');
if (window.JSON) {
output.val(window.JSON.stringify(list.nestable('serialize')));//, null, 2));
} else {
output.val('JSON browser support required for this application.');
}
};
// activate Nestable for list 1
$('#nestable').nestable({
group: 1
})
.on('change', updateOutput);
// activate Nestable for list 2
$('#nestable2').nestable({
group: 1
})
.on('change', updateOutput);
// output initial serialised data
$('#nestable2').attr('data-id', 'newvalue');
$('#nestable2').data('id', 'newvalue');
updateOutput($('#nestable').data('output', $('#nestable-output')));
updateOutput($('#nestable2').data('output', $('#nestable2-output')));
});
It only fails sometimes. then if i re-order the list in the second container it updates, but won't update any new items until i re-order again. Any help is greatly appreciated.
I found the answer. The issue was in the jquery.nestable.js file around line 475-ish is this:
$(this).data("nestable-id", new Date().getTime());
on faster machines it seems there wasn't enough time in milliseconds for the script to see a change had taken place. Replaced with this:
$(this).data("nestable-id", Math.round(Math.random() * Math.pow(10, 16)));
Any generation of a random number it seems would do, so this answer isn't the only way it could be done.
链接地址: http://www.djcxy.com/p/59070.html上一篇: 使用二进制数据显示图像的一部分
下一篇: jquery nestable不更新