Viima JQuery评论 - GetUsers(Pinged用户)在partialview中显示不正确

Axl*_*ack 8 html javascript c# jquery json

参考

附件

描述

我有一个带有"文章"列表的视图,列表中的每个"文章"上都有一个"阅读更多"按钮.当我点击read more按钮时,会打开一个模态,其中包含一个带有jquery注释的局部视图.但是,当我搜索ping用户(使用@符号)时,用户列表不显示textarea,而是在模态中更高(远离textarea).

下面是一张图片,然后是我的代码.您将在图像的底部看到我已经放置了"@"符号,并且用户列表显示在顶部,它应该是由textarea.似乎当我点击列表中较低的文章时,当我按下"@"符号时,用户列表中显示的列表越高:

在此输入图像描述

MVC视图

下面是填充调用模态的"文章"的部分:

@{
    int iGroupNameId = 0;
    int iTotalArticles = 0;
    foreach (var groupItems in Model.ArticleGroups)
    {
        iTotalArticles = Model.ArticlesList.Where(x => x.fkiGroupNameId == groupItems.pkiKnowledgeSharingCenterGroupsId).Count();
        if (iTotalArticles > 0)
        {
            <div style="background: linear-gradient(#B5012E, darkred); margin: 10px; padding: 10px; font-weight: bold; color: white; text-transform: uppercase;">@groupItems.GroupName</div><div class="container" style="width:100%">
                @if (groupItems.pkiKnowledgeSharingCenterGroupsId != iGroupNameId)
                {
                    foreach (var item in Model.ArticlesList.Where(x => x.fkiGroupNameId == groupItems.pkiKnowledgeSharingCenterGroupsId))
                    {
                        <div class="row">
                            <div class="col-md-4">
                                @if (User.IsInRole("Administrator"))
                                {
                                    <div class="pull-right">
                                        <div class="btn-group">
                                            <button class="btn dropdown-toggle btn-xs btn-info" data-toggle="dropdown">
                                                <i class="fa fa-gear"></i> <i class="fa fa-caret-down"></i>
                                            </button>
                                            <ul class="dropdown-menu pull-right">
                                                <li>
                                                    <a href="@Url.Action("EditArticle", "ILearn", new { id = item.KnowledgeSharingArticlesId })">Edit</a>
                                                </li>
                                                <li class="divider"></li>
                                                <li>
                                                    <a href="@Url.Action("DeleteArticle", "ILearn", new { id = item.KnowledgeSharingArticlesId })">Delete</a>
                                                </li>
                                            </ul>

                                        </div>
                                    </div>
                                }

                                <img src="@item.ArticleImage" class="img-responsive" alt="img" style="width:350px;height:200px">
                                <ul class="list-inline padding-10">
                                    <li>
                                        <i class="fa fa-calendar"></i>
                                        @item.DateTimeStamp.ToLongDateString()
                                    </li>
                                    <li>
                                        <i class="fa fa-comments"></i>
                                        @item.ArticleComments
                                    </li>
                                    <li>
                                        <i class="fa fa-eye"></i>
                                        @item.ArticleViews
                                    </li>
                                </ul>
                            </div>
                            <div class="col-md-8 padding-left-0">
                                <h6 class="margin-top-0"> <span style="font-size:large">@item.Title</span><br><small class="font-xs"><i>Published by <a href="@Url.Action("GetProfileData","UserProfile", new { userid = item.fkiUserId })">@item.User_FullName</a></i></small></h6>
                                <p>
                                    @Html.Raw(item.Description)
                                </p>
                                @*<a class="btn btn-danger" href="@Url.Action("ShowArticleDetails", "ILearn", new { id = item.KnowledgeSharingArticlesId })">Read more</a>*@
                                <button type="button" onclick="showArticle('@item.KnowledgeSharingArticlesId')" class="btn btn-danger" data-target="#show-details-modal" data-toggle="modal">
                                    Read more
                                </button>
                            </div>
                        </div>
                        <hr>
                    }
                }
            </div>
        }

    }
}
Run Code Online (Sandbox Code Playgroud)

语气

它位于页面顶部(在@model appname.ViewModels.VM下):

<!--Loading Panel-->
<div id="loadingPanel" style="display: none;">
    <div class="progress progress-striped active">
        <div class="progress-bar progress-bar-info" style="width: 100%">...LOADING...</div>
    </div>
</div>

<!-- Show details modal-->
<div id="show-details-modal" class="modal fade" style="width:100%">
    <div class="modal-dialog modal-xl">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title"></h4>
                <div id="loadingPanelShowDetails" class="col-md-12 text-center" style="display: none;">
                    <br />
                    <div class="progress progress-striped active">
                        <div class="progress-bar progress-bar-info" style="width: 100%">...LOADING...</div>
                    </div>
                </div>
                <div id="target-show-details">

                </div>
            </div>
        </div>
    </div>
</div>
Run Code Online (Sandbox Code Playgroud)

Jquery代码

function showArticle(id) {
$("#target-show-details").html('');
$('#loadingPanelShowDetails').show();
$.ajax({
    type: 'get',
    url: '@Url.Action("ShowArticleDetails", "ILearn")',
    contentType: 'application/json; charset=utf-8',
    dataType: 'html',
    data: { "id": id },
    success: function (result) {
        $("#target-show-details").html(result);
        $('#loadingPanelShowDetails').hide();

        var saveComment = function (data) {
            $(data.pings).each(function (index, id) {
                var user = usersArray.filter(function (user) { return user.id == id })[0];
                alert(user.fullname);
                data.content = data.content.replace('@@' + id, '@@' + user.fullname);
            });

            return data;
        }
        $('#articlecomments-container').comments({
            profilePictureURL: 'https://viima-app.s3.amazonaws.com/media/public/defaults/user-icon.png',
            currentUserId: 1,
            roundProfilePictures: true,
            textareaRows: 1,
            enableAttachments: true,
            enableHashtags: true,
            enablePinging: true,
            getUsers: function (success, error) {
                $.ajax({
                    type: 'get',
                    traditional: true,
                    url: '@Url.Action("GetPinnedUsers", "ILearn")',
                    success: function (usersArray) {
                        success(usersArray)
                    },
                    error: error
                });
            },
            getComments: function (success, error) {
                $.ajax({
                    type: 'get',
                    traditional: true,
                    data: { "id": id },
                    url: '@Url.Action("GetArticleComments", "ILearn")',
                    success: function (commentsArray) {
                        success(saveComment(commentsArray))
                    },
                    error: error
                });
            },
            postComment: function (data, success, error) {
                $.ajax({
                    type: 'post',
                    dataType: "json",
                    url: '@Url.Action("PostArticleComment", "ILearn")',
                    data: { "CVM": data, "articleId": id },
                    success: function (comment) {
                        success(comment);
                    },
                    error: error
                });
            },
            putComment: function (data, success, error) {
                $.ajax({
                    type: 'post',
                    dataType: "json",
                    url: '@Url.Action("PutArticleComment", "ILearn")',
                    data: { "CVM": data, "articleId": id },
                    success: function (comment) {
                        success(comment);
                    },
                    error: error
                });
            },
            deleteComment: function (data, success, error) {
                $.SmartMessageBox({
                    title: "Deleting Comment?",
                    content: "Are you sure that you want to delete this comment?",
                    buttons: '[No][Yes]'
                }, function (ButtonPressed) {
                    if (ButtonPressed === "Yes") {
                        $.ajax({
                            type: 'post',
                            dataType: "json",
                            url: '@Url.Action("DeleteArticleComment", "ILearn")',
                            data: { "CVM": data, "articleId": id },
                            success: function (data) {
                                if (data.status === "usersuccess") {
                                    $.smallBox({
                                        title: "<strong>Comment Deleted</strong>",
                                        content: "<i class='fa fa-clock-o'></i> <i>Comment was successfully deleted! <strong</strong></i>",
                                        color: "#659265",
                                        iconSmall: "fa fa-check fa-2x fadeInRight animated",
                                        timeout: 4000
                                    });
                                    success();
                                } else {
                                    success();
                                }
                            }
                        });
                    }
                    if (ButtonPressed === "No") {
                        $.smallBox({
                            title: "<strong>Comment not deleted</strong>",
                            content: "<i class='fa fa-clock-o'></i> <i>This comment has not been deleted.</i>",
                            color: "#C46A69",
                            iconSmall: "fa fa-times fa-2x fadeInRight animated",
                            timeout: 4000
                        });
                    }

                });
                e.preventDefault();
            },
            upvoteComment: function (data, success, error) {
                if (data.user_has_upvoted) {
                    $.ajax({
                        type: 'post',
                        dataType: "json",
                        url: '@Url.Action("UpVoteArticleComment", "ILearn")',
                        data: { "CVM": data, "articleId": id },
                        success: function () {
                            success(data)
                        },
                        error: error
                    });
                } else {
                    $.ajax({
                        type: 'post',
                        url: '@Url.Action("DeleteArticleCommentUpvote", "ILearn")',
                        data: { "commentId": data.id },
                        success: function () {
                            success(commentJSON)
                        },
                        error: error
                    });
                }
            },
            uploadAttachments: function (commentArray, success, error) {
                var responses = 0;
                var successfulUploads = [];

                var serverResponded = function () {
                    responses++;

                    // Check if all requests have finished
                    if (responses == commentArray.length) {

                        // Case: all failed
                        if (successfulUploads.length == 0) {
                            error();

                            // Case: some succeeded
                        } else {
                            success(successfulUploads)
                        }
                    }
                }

                $(commentArray).each(function (index, commentJSON) {

                    // Create form data
                    var formData = new FormData();
                    $(Object.keys(commentJSON)).each(function (index, key) {
                        var value = commentJSON[key];
                        if (value) formData.append(key, value);
                    });

                    formData.append('fkiKnowledgeSharingArticlesId', id);

                    $.ajax({
                        url: '@Url.Action("UploadToArticleComments", "ILearn")',
                        type: 'POST',
                        data: formData,
                        cache: false,
                        contentType: false,
                        processData: false,
                        success: function (commentJSON) {
                            successfulUploads.push(commentJSON);
                            serverResponded();
                        },
                        error: function (data) {
                            serverResponded();
                        },
                    });
                });
            }
        });

    },
    error: function (xhr, textStatus, errorThrown) {
        alert(xhr.responseText);
    }
});
}
Run Code Online (Sandbox Code Playgroud)

MVC部分视图

@model Innovation_Cafe.Models.KnowledgeSharingArticles
<div class="col-lg-12">
    <div class="margin-top-10">
        <div style="text-align:center;border:solid;border-style:solid">
            <img src="@Model.ArticleImage" class="img-responsive" alt="img" style="width:100%;">
        </div>
        <ul class="list-inline padding-10">
            <li>
                <i class="fa fa-calendar"></i>
                @Model.DateTimeStamp.ToLongDateString()
            </li>
            <li>
                <i class="fa fa-comments"></i>
                @Model.ArticleComments
            </li>
            <li>
                <i class="fa fa-eye"></i>
                @Model.ArticleViews
            </li>
        </ul>
    </div>
</div>
<div class="col-lg-12">
    <h6 class="margin-top-0"> @Model.Title<br><small class="font-xs"><i>Published by <a href="@Url.Action(" GetProfileData","UserProfile", new { userid=Model.fkiUserId })">@Model.User_FullName</a></i></small></h6>
    <br />
    <p>
        @Html.Raw(Model.Description)
    </p>
    <p>
        @if (Model.FileType == ".mp4")
            {
            <div style="text-align:center;border-style:solid">
                <video controls width="100%">
                    <source src="@Model.FilePath" type="video/mp4" />
                </video>
            </div>
        }
        else
        {
            if (Model.FilePath !=null)
            {
            <p>Click here to view file: <a href="@Model.FilePath" target="_blank">Click here</a></p>
            }
        }

    </div>
    <div class="col-md-12">
        <p>&nbsp;</p>
        <hr style="border:solid" />
    </div>
    <div class="row col-md-12">
        <div class="col-md-12" id="articlecomments-container">

        </div>
    </div>
Run Code Online (Sandbox Code Playgroud)

在局部视图的底部是这个div,它被填充:

<div class="row col-md-12">
    <div class="col-md-12" id="articlecomments-container">

    </div>
</div>
Run Code Online (Sandbox Code Playgroud)

编辑

花了很长时间浏览jquery-comments.js文件之后,我发现在这里显示了ping用户:

 // CUSTOM CODE
 // ========================================================================================================================================================================================
 // Adjust vertical position
    var top = parseInt(this.$el.css('top')) + self.options.scrollContainer.scrollTop();
    this.$el.css('top', top); 
Run Code Online (Sandbox Code Playgroud)

这似乎是采用View的css('top'),这会导致部分视图上用户ping的问题.

Ole*_*rov 2

发生此问题的原因是您错误的引导布局:您必须将所有内容包含col到 中row,而在您的示例中,您使用rawandcol-md-12来表示同一个容器。

在我正确地将列包含到row元素中后,一切都开始正常工作。换句话说,最后一节就这样写:

<div class="row">
    <div class="col-md-12" id="articlecomments-container">

    </div>
</div>
Run Code Online (Sandbox Code Playgroud)

请看一下Bootstrap 4 中的嵌套示例。

更新

感谢您在页面上绘制大量文章的提示,我成功地重现了该错误。这个问题确实是因为滚动,尽管原因似乎在jquery.textcomplete.js函数中更深入_fitToBottom(它考虑了主窗口滚动,但不考虑嵌入的模式容器)。然而,我使用的更快的方法而不是纠正那个复杂的逻辑,正是在您指向的位置(而不是您显示的最后两行):

var topPoint = self.options.scrollContainer[0].offsetTop;
var scrolledWindow = self.options.scrollContainer.parents().filter(function () {
    return this.scrollTop > 0;
})[0];
var spaceAvailable = $(window).height() - (topPoint - scrolledWindow.scrollTop);

var elHeight = this.$el.height();
this.$el.css('top', spaceAvailable > elHeight ? topPoint: topPoint - elHeight);         
Run Code Online (Sandbox Code Playgroud)

该逻辑基于寻找最近的带滚动的父级,然后测量剩余空间是否足以渲染下拉列表以找出其最终位置。它可能会稍微错过指针,但尽管滚动仍然可以正常工作。我已经在 Chrome 和 Firefox 中尝试过。希望它能引导您找到自己的方法。