相关联文章操作

 

文章相关联操作

<div class="control-group">
        <label class="control-label">相关文章:</label>

        <div class="controls">
            <form:hidden id="articleDataRelation" path="articleData.relation" htmlEscape="false" maxlength="200"
                         class="input-xlarge"/>
            <ol id="articleSelectList"></ol>
            <a id="relationButton" href="javascript:" class="btn">添加相关</a>
            <script type="text/javascript">
                var articleSelect = [];
                function articleSelectAddOrDel(id, title) {
                    var isExtents = false, index = 0;
                    for (var i = 0; i < articleSelect.length; i++) {
                        if (articleSelect[i][0] == id) {
                            isExtents = true;
                            index = i;
                        }
                    }
                    if (isExtents) {
                        articleSelect.splice(index, 1);
                    } else {
                        articleSelect.push([id, title]);
                    }
                    articleSelectRefresh();
                }
                function articleSelectRefresh() {
                    $("#articleDataRelation").val("");
                    $("#articleSelectList").children().remove();
                    for (var i = 0; i < articleSelect.length; i++) {
                        $("#articleSelectList").append("<li>" + articleSelect[i][1] + "&nbsp;&nbsp;<a href=\"javascript:\" onclick=\"articleSelectAddOrDel('" + articleSelect[i][0] + "','" + articleSelect[i][1] + "');\">×</a></li>");
                        $("#articleDataRelation").val($("#articleDataRelation").val() + articleSelect[i][0] + ",");
                    }
                }
                $.getJSON("${ctx}/cms/article/findByIds", {ids: $("#articleDataRelation").val()}, function (data) {
                    for (var i = 0; i < data.length; i++) {
                        articleSelect.push([data[i][1], data[i][2]]);
                    }
                    articleSelectRefresh();
                });
                $("#relationButton").click(function () {
                    top.$.jBox.open("iframe:${ctx}/cms/article/selectList?pageSize=8", "添加相关", $(top.document).width() - 220, $(top.document).height() - 180, {
                        buttons: {"确定": true}, loaded: function (h) {
                            $(".jbox-content", top.document).css("overflow-y", "hidden");
                        }
                    });
                });
            </script>
        </div>
    </div>

 

posted @ 2017-08-10 15:06  随行-LV  阅读(300)  评论(0编辑  收藏  举报