【问题标题】:Jquery sortable-ui inside a dialog-ui that loads a page via ajax通过ajax加载页面的对话框ui中的Jquery sortable-ui
【发布时间】:2012-07-28 00:40:27
【问题描述】:

我有一个用 CakePHp v1.3 编写的用户管理系统,我想对用户进行排序。 所以我正在使用 jquery dialog-ui(假设类似于 facebook 好友列表)并通过添加最新用户的 ajax 页面加载它。

在这个列表中,我希望能够使用 jquery sortable-ui,但由于某种原因我不能。 我猜javascript没有加载? 如果发生这种情况,我无法在萤火虫中看到,所以如果有人知道可以做什么,请帮助我。

代码如下: 这会触发对话框:

<div onClick="manageCoauthors(data={'id':'<?php echo $this->params['pass'][0]; ?>'});" class="floatRight allImg leftManageFDs" style="cursor: pointer"></div>

那么这是打开对话框的javascript:

$('#dialog-manage-coauthors').load(fdBaseUrl + 'publications/ajaxManageCoauthors/' + paperID).dialog({
        resizable: false,
        modal: true,
        width:500,
        height:400,
        buttons:{
            "OK": function(){
                $(this).dialog('close');
            }
        }
    });

以及使用 ajax 加载的页面内容将填充 dialog-ui 容器

<style>
#sortable { list-style-type: none; margin: 0; padding: 0; cursor: move }
#sortable li { margin: 3px 3px 3px 0; padding: 1px; float: left; width: 50px; height: 50px; font-size: 4em; text-align: center; }
</style>

<script type="text/javascript">
$(document).ready(function(){
    //initialize sortable
    $("#sortable").sortable({
        /*update: function(){
            var order = $('#sortable').sortable('serialize');
            $.ajax({
                url: fdBaseUrl + 'cv/orderParahraphs',
                data: order,
                dataType: 'json'
            })
        }*/
    });
    $( "#sortable" ).disableSelection();
});



</script>
<?php
    if(isset($publicationColaborators) && !empty($publicationColaborators)){
        ?>
        <ul id="sortable" class="ui-sortable">
        <?php
        foreach($publicationColaborators as $colaboratorDetail){

            //debug($colaboratorDetail);
            $profile_image = 'users/profile/' . 
                                md5((isset($colaboratorDetail['User']) ? $colaboratorDetail['User']['id'] : $colaboratorDetail['id'])) . DS . 
                                (isset($colaboratorDetail['User']) ? $colaboratorDetail['User']['profile_photo'] : $colaboratorDetail['profile_photo']);
            $options = array('gender'=>(isset($colaboratorDetail['User']) ? $colaboratorDetail['User']['gender'] : $colaboratorDetail['gender']), 
                                'size' => '40',
                                'link'=>(isset($colaboratorDetail['User']) ? $colaboratorDetail['User']['slug'] : $colaboratorDetail['slug']),
                                'title'=>$this->Fellow->fullUserVisitCard((isset($colaboratorDetail['User']) ? $colaboratorDetail['User'] : $colaboratorDetail)));
            ?>
            <li class="ui-state-default">
                <div class="floatLeft" style="padding:10px;">

                        <div onClick="removeColaborator(data={'id':'<?php echo (isset($colaboratorDetail['User']) ? $colaboratorDetail['User']['id'] : $colaboratorDetail['id']); ?>', 'paperID':'<?php echo $paperID; ?>'})" style="position: absolute; margin-left:27px" class="allImg wall_post_actions_delete_active"></div>
                        <?php
                        echo $this->Fellow->checkImage($profile_image, $options); 
                        ?>

                </div>
            </li>
            <?php
        }
        ?>
        </ul>
        <?php
    }
    else{
        echo __d('publications', 'You have no co-authors yet', true); 
    }
?>
<div class="clearDiv"></div>

【问题讨论】:

    标签: jquery ajax jquery-ui cakephp jquery-ui-dialog


    【解决方案1】:

    我认为这里的问题是 document.ready 调用不会在 AJAX 内容上重新触发,因此您的 sortable 永远不会被调用。

    您需要做的是在load 函数的下一个参数中添加可排序对象,这是一个在load() 本身完成时触发的回调。

    $('#dialog-manage-coauthors').load(fdBaseUrl + 'publications/ajaxManageCoauthors/' + paperID, function() {
        //initialize sortable
        $("#sortable").sortable({
            /*update: function(){
                var order = $('#sortable').sortable('serialize');
                $.ajax({
                    url: fdBaseUrl + 'cv/orderParahraphs',
                    data: order,
                    dataType: 'json'
                })
            }*/
        });
        $( "#sortable" ).disableSelection();
    }).dialog({
            resizable: false,
            modal: true,
            width:500,
            height:400,
            buttons:{
                "OK": function(){
                    $(this).dialog('close');
                }
            }
        });
    

    这显然会进入父页面。

    【讨论】:

    • 不,我之前也尝试过这个,但是 sortable 不存在来做他的事情。也许你可以给我一个提示如何调试它并检查 ajax 页面附带的内容?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2010-12-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多