简体   繁体   English

SharePoint 2007 和 Javascript/JSQuery/SPServices - 循环遍历列表并更新每个项目

[英]SharePoint 2007 and Javascript/JSQuery/SPServices - Loop through list and update each item

please can you assist with the below.请您协助以下事项。 Any advice is appreciated.任何建议表示赞赏。 Many thanks.非常感谢。

Solution Contents解决方案内容

  1. SharePoint 2007 List SharePoint 2007 列表
  2. SharePoint List Columns: CreatedDate, DueDate, DaysRemaining SharePoint 列表列:CreatedDate、DueDate、DaysRemaining
  3. Coding Script Language: Javascript/JQuery/SPServices?编码脚本语言:Javascript/JQuery/SPServices?

Solution A SharePoint 2007 list that contains tasks and the days remaining to complete those tasks.解决方案包含任务和完成这些任务的剩余天数的 SharePoint 2007 列表。 The days remaining MUST NOT include public holidays or weekends.剩余天数不得包括公共假期或周末。 The DaysRemaining column must update when the page is loaded so correct value is displayed each day. DaysRemaining 列必须在页面加载时更新,以便每天显示正确的值。

Solution Issue The best solution would be to use SharePoint calculated columns, which work great from my experience, however they do not exclude weekends for the calculation.解决方案问题最好的解决方案是使用 SharePoint 计算列,根据我的经验,这非常有效,但是它们不排除周末进行计算。 So, I am planning on using JS to do the calculation of DaysRemaining on page load.所以,我打算使用 JS 来计算页面加载时的 DaysRemaining。

I require a way of looping through a SharePoint 2007 list, and then for each item in that list update the DaysRemaining column.我需要一种循环遍历 SharePoint 2007 列表的方法,然后为该列表中的每个项目更新 DaysRemaining 列。

Could you please point me in the right direction?你能指出我正确的方向吗?

I assume a for loop, and some sort of update function?我假设有一个 for 循环和某种更新功能? I have successfully used the SPServices.SPMultipleUpdateItems but that updates a list column with the same value, not a different value for each list item.我已经成功地使用了 SPServices.SPMultipleUpdateItems,但是它更新了一个具有相同值的列表列,而不是每个列表项的不同值。

I dont have too much experience past migrations in 2007 but I think you are going at this the wrong way.我在 2007 年的迁移过程中没有太多经验,但我认为您走错了路。

why not just add to the formula of the calculated column.为什么不直接添加到计算列的公式中。

if its an integer value you could do something like:如果它是一个整数值,您可以执行以下操作:

= (number of days) / 7 * 5 =(天数)/ 7 * 5

If you cant do it all in one column, make a second column.如果您不能在一栏中完成所有操作,请制作第二栏。 First calc column finds integer value of days.第一个计算列查找天数的整数值。 Second calc column does math operations using that first column.第二个 calc 列使用第一列进行数学运算。

I am not allowed to comment on your post because my reputation is not high enough.我不能评论你的帖子,因为我的声誉不够高。

So forgive me using the answer option for maybe a non-answer.所以请原谅我使用答案选项可能是非答案。

What happens in 2007 if you create a Calculated Column with formula:如果您使用公式创建计算列,2007 年会发生什么:

="<B>Hello World!</B>"

AND set the datatype to Number并将数据类型设置为数字

In 2010,2013 and Online it will output the correct Bold text, that means you can use JavaScript code in there as well在 2010、2013 和 Online 中,它将输出正确的粗体文本,这意味着您也可以在其中使用 JavaScript 代码

If 2007 displays the string as <B>Hello World!</B> you are out of luck and can't use this approach in 2007如果 2007 将字符串显示为 <B>Hello World!</B> 你就不走运并且不能在 2007 中使用这种方法

FYI a DaysRemaing calculation relies on the current date;仅供参考,DaysRemaing 计算依赖于当前日期; but TODAY is not available in Calculated Columns.但 TODAY 在计算列中不可用。 Since Calculated Columns are only updated on Item update any use of TODAY will be 1 day off tomorrow, 2 days off the day after etc. That's why using JavaScript to do the calculation in a VIEW is a viable workaround.由于计算列仅在项目更新时更新,因此任何使用 TODAY 的明天都会休息 1 天,后天休息 2 天等等。这就是为什么使用 JavaScript 在 VIEW 中进行计算是一种可行的解决方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM