Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
346 views
in Technique[技术] by (71.8m points)

javascript - 如何在共享点列表中循环执行以下代码(How to do the following code in loop in sharepoint list)

Here I have get the count from my sharepoint list when status is open and the created month is jan,feb,etc...The month field is a calculated column and it calculated the months of created field .....Here is my code(在这里,当状态为打开并且创建的月份为jan,feb等时,我可以从共享列表中获取计数。month字段是计算列,它计算了创建字段的月份...这是我的码)

var month1 = '<View><Query><Where><And><Eq><FieldRef Name="Status"/><Value Type="Text">Open</Value></Eq><Eq><FieldRef Name="Monthname"/><Value Type="Text">Jan</Value></Eq></And></Where></Query></View>'; var month2 = '<View><Query><Where><And><Eq><FieldRef Name="Status"/><Value Type="Text">Open</Value></Eq><Eq><FieldRef Name="Monthname"/><Value Type="Text">Feb</Value></Eq></And></Where></Query></View>'; var month3 = '<View><Query><Where><And><Eq><FieldRef Name="Status"/><Value Type="Text">Open</Value></Eq><Eq><FieldRef Name="Monthname"/><Value Type="Text">Mar</Value></Eq></And></Where></Query></View>'; var month4 = '<View><Query><Where><And><Eq><FieldRef Name="Status"/><Value Type="Text">Open</Value></Eq><Eq><FieldRef Name="Monthname"/><Value Type="Text">Apr</Value></Eq></And></Where></Query></View>'; var month5 = '<View><Query><Where><And><Eq><FieldRef Name="Status"/><Value Type="Text">Open</Value></Eq><Eq><FieldRef Name="Monthname"/><Value Type="Text">May</Value></Eq></And></Where></Query></View>'; var month6 = '<View><Query><Where><And><Eq><FieldRef Name="Status"/><Value Type="Text">Open</Value></Eq><Eq><FieldRef Name="Monthname"/><Value Type="Text">Jun</Value></Eq></And></Where></Query></View>'; var month7 = '<View><Query><Where><And><Eq><FieldRef Name="Status"/><Value Type="Text">Open</Value></Eq><Eq><FieldRef Name="Monthname"/><Value Type="Text">Jul</Value></Eq></And></Where></Query></View>'; var month8 = '<View><Query><Where><And><Eq><FieldRef Name="Status"/><Value Type="Text">Open</Value></Eq><Eq><FieldRef Name="Monthname"/><Value Type="Text">Aug</Value></Eq></And></Where></Query></View>'; var month9 = '<View><Query><Where><And><Eq><FieldRef Name="Status"/><Value Type="Text">Open</Value></Eq><Eq><FieldRef Name="Monthname"/><Value Type="Text">Sep</Value></Eq></And></Where></Query></View>'; var month10 = '<View><Query><Where><And><Eq><FieldRef Name="Status"/><Value Type="Text">Open</Value></Eq><Eq><FieldRef Name="Monthname"/><Value Type="Text">Oct</Value></Eq></And></Where></Query></View>'; var month11 = '<View><Query><Where><And><Eq><FieldRef Name="Status"/><Value Type="Text">Open</Value></Eq><Eq><FieldRef Name="Monthname"/><Value Type="Text">Nov</Value></Eq></And></Where></Query></View>'; var month12 = '<View><Query><Where><And><Eq><FieldRef Name="Status"/><Value Type="Text">Open</Value></Eq><Eq><FieldRef Name="Monthname"/><Value Type="Text">Dec</Value></Eq></And></Where></Query></View>'; this contains the caml query for get the count for each months(它包含caml查询以获取每个月的计数) var monthquery1 = new SP.CamlQuery(); monthquery1.set_viewXml(month1); var monthitem1 = TicketList.getItems(monthquery1); var monthquery2 = new SP.CamlQuery(); monthquery2.set_viewXml(month2); var monthitem2 = TicketList.getItems(monthquery2); var monthquery3 = new SP.CamlQuery(); monthquery3.set_viewXml(month3); var monthitem3 = TicketList.getItems(monthquery3); var monthquery4 = new SP.CamlQuery(); monthquery4.set_viewXml(month4); var monthitem4 = TicketList.getItems(monthquery4); var monthquery5 = new SP.CamlQuery(); monthquery5.set_viewXml(month5); var monthitem5 = TicketList.getItems(monthquery5); var monthquery6 = new SP.CamlQuery(); monthquery6.set_viewXml(month6); var monthitem6 = TicketList.getItems(monthquery6); var monthquery7 = new SP.CamlQuery(); monthquery7.set_viewXml(month7); var monthitem7 = TicketList.getItems(monthquery7); var monthquery8 = new SP.CamlQuery(); monthquery8.set_viewXml(month8); var monthitem8 = TicketList.getItems(monthquery8); var monthquery9 = new SP.CamlQuery(); monthquery9.set_viewXml(month9); var monthitem9 = TicketList.getItems(monthquery9); var monthquery10 = new SP.CamlQuery(); monthquery10.set_viewXml(month10); var monthitem10 = TicketList.getItems(monthquery10); var monthquery11 = new SP.CamlQuery(); monthquery11.set_viewXml(month11); var monthitem11 = TicketList.getItems(monthquery11); var monthquery12 = new SP.CamlQuery(); monthquery12.set_viewXml(month12); var monthitem12 = TicketList.getItems(monthquery12); context.load(monthitem1); context.load(monthitem2); context.load(monthitem3); context.load(monthitem4); context.load(monthitem5); context.load(monthitem6); context.load(monthitem7); context.load(monthitem8); context.load(monthitem9); context.load(monthitem10); context.load(monthitem11); context.load(monthitem12); and here i will load the data to my list .....(然后我将数据加载到我的列表中.....) context.executeQueryAsync( function () { var monthid1 = monthitem1.get_count(); var monthid2 = monthitem2.get_count(); var monthid3 = monthitem3.get_count(); var monthid4 = monthitem4.get_count(); var monthid5 = monthitem5.get_count(); var monthid6 = monthitem6.get_count(); var monthid7 = monthitem7.get_count(); var monthid8 = monthitem8.get_count(); var monthid9 = monthitem9.get_count(); var monthid10 = monthitem10.get_count(); var monthid11 = monthitem11.get_count(); var monthid12 = monthitem12.get_count(); }); And this success function to get the count of my caml query..(这个成功函数可以获取我的caml查询的计数。) Now what is problem is i don't know how to do this in loop function.. how can i achieve this in a while loop please help me(现在的问题是我不知道如何在循环功能中执行此操作。如何在while循环中实现此功能,请帮助我) or Is there any other ways to get the count for each months??(还是还有其他方法可以获取每个月的计数??)   ask by Pakkiya Nathan translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

We can use REST API with jQuery Ajax to achieve it.(我们可以将REST API与jQuery Ajax结合使用来实现。)

<script src="https://code.jquery.com/jquery-1.12.4.min.js" type="text/javascript"></script> <script type="text/javascript"> $(function () { var month=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"]; for(var i=0;i<month.length;i++){ var monthCount=getItemCountByFilter("$filter=Status eq 'Open' and Monthname eq '"+month[i]+"'"); $("#allData").append("<p>"+month[i]+":"+monthCount+"</p>"); } }); function getItemCountByFilter(filter){ var count=0; $.ajax({ url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getbytitle('TaskList')/items?$top=5000&$select=ID&"+filter, type: "GET", async:false, headers: { "Accept": "application/json;odata=verbose", }, success: function (data) { count=data.d.results.length; }, error: function (error) { console.log(JSON.stringify(error)); } }); return count; } </script> <div id="allData"/>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...