gpt4 book ai didi

javascript - 如何在共享点列表中循环执行以下代码

转载 作者:行者123 更新时间:2023-12-01 00:25:00 24 4
gpt4 key购买 nike

这里,当状态打开且创建的月份为一月、二月等时,我从共享点列表中获取了计数...月份字段是一个计算列,它计算了创建字段的月份.....这是我的代码

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>';

这包含用于获取每个月计数的 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);

在这里我将把数据加载到我的列表中......

                        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();
});

这个成功函数可以获取我的 caml 查询的计数..

现在的问题是我不知道如何在循环函数中执行此操作..我怎样才能在 while 循环中实现这一点请帮助我

或者还有其他方法可以获取每个月的计数吗?

最佳答案

我们可以使用 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"/>

关于javascript - 如何在共享点列表中循环执行以下代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59086306/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com