Display number of replies in disscussion board
how to display number of replies in disscussion board
I have a require about display the replies' number in disscussion board, finish it via jQuery.
First, get the number of the replies of each items via client object model,
then store the number into array.
at last, show it in page via jQuery .
here is the code.
<script type="text/javascript"> $(document).ready(function(){ ExecuteOrDelayUntilScriptLoaded(retrieveListItems, "SP.js"); }); function retrieveListItems() { var clientContext = new SP.ClientContext.get_current(); var oList = clientContext.get_web().get_lists().getByTitle('Dis1'); var camlQuery = new SP.CamlQuery(); camlQuery.set_viewXml('<View><Query>' + '<OrderBy>'+ '<FieldRef Name="DiscussionLastUpdated" Ascending="False"></FieldRef>'+ '</OrderBy>'+ '</Query><RowLimit>20</RowLimit></View>'); this.collListItem = oList.getItems(camlQuery, 'Include(ItemChildCount)'); clientContext.load(collListItem); clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed)); } function onQuerySucceeded(sender, args) { var arr = new Array(); var listItemInfo = ''; var listItemEnumerator = collListItem.getEnumerator(); arr.length = 0; while (listItemEnumerator.moveNext()) { var oListItem = listItemEnumerator.get_current(); listItemInfo = oListItem.get_item('ItemChildCount'); arr.push(listItemInfo); } $('#forum0-PostList>li').each(function(index){ $(this).find('div.ms-comm-postMainContainer').css({"float":"left", "width":"90%"}); var arrValue = arr.shift() $(this).find('div.ms-comm-postMainContainer').after("<div class = 'div_showNumber' style = 'float:left;font-size:20px;width:10%;background-color:gray;color:white;width:30px;height:30px;text-align:center;'>" + arrValue + "</div>"); }); } function onQueryFailed(sender, args) { alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace()); } </script>
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步