问题描述
我正在尝试限制 SharePoint 2010 列表中允许的条目数.该列表供用户注册,例如,我们希望将其限制为 60.我看过类似的问题,但似乎没有一个有效.
I am trying to limit the number of entries allowed on a SharePoint 2010 list . The list is for users to sign up to and we want to limit this to 60 for example. I have had a look at the similar questions but none of them seem to work.
迄今为止发现的所有验证公式都不合适.我将不胜感激对此的任何建议和帮助.
None of the validation formulas found so far have been appropriate. I would appreciate any advice and help on this .
提前谢谢!:)
推荐答案
没有任何内置功能可以让您完成此操作.但是,如果您提供自己的用于创建条目的界面(例如自定义注册页面),您可以控制行为并在达到限制后阻止注册.
There's nothing built-in to allow you to accomplish this. However, if you present your own interface for creating entries (such as a custom sign-up page) you can control the behavior and prevent signups after the limit is reached.
为了帮助您入门,这里有一个使用 JavaScript 对象模型来查询列表并在创建项目之前检测项目计数的示例.
To get you started, here's an example of using the JavaScript object model to query the list and detect the item count before creating an item.
<input type="button" value="Sign Up Now!" onclick="createItemIfBelowLimit()" />
<script>
function createItemIfBelowLimit(){
var max = 60;
var listTitle = "Your List Title";
var clientContext = new SP.ClientContext();
var list = clientContext.get_web().get_lists().getByTitle(listTitle);
clientContext.load(list);
clientContext.executeQueryAsync(function(){
var itemCount = list.get_itemCount();
if(itemCount < max){
createItem(listTitle,{
"Title":"Example title text",
"Body":"Example body text"
});
}else{
alert("This sign-up list is full. Sorry!");
}
},function(sender,args){
alert(args.get_message());
});
}
function createItem(listTitle,values){
var clientContext = new SP.ClientContext();
var list = clientContext.get_web().get_lists().getByTitle(listTitle);
var newItem = list.addItem();
for(var key in values){
newItem.set_item(key,values[key]);
}
newItem.update();
clientContext.load(newItem);
var rootFolder = list.get_rootFolder(); // Note: use a list's root folder to determine its server relative URL
clientContext.load(rootFolder);
clientContext.executeQueryAsync(function(){
var itemId = newItem.get_item("ID");
SP.UI.ModalDialog.showModalDialog(
{
title: "Item #"+itemId+" Created Successfully!",
url: rootFolder.get_serverRelativeUrl() + "/DispForm.aspx?ID="+itemId
}
);
},function(sender,args){
alert(args.get_message());
});
}
</script>
要使用上述代码,请先将其保存为文本文件,然后将其上传到 SharePoint 网站上的库中.然后,您可以在您的网站上创建一个页面,将内容编辑器 Web 部件添加到该页面,并编辑该内容编辑器 Web 部件的 Web 部件属性.在内容链接"属性中,粘贴文本文件的链接;这将导致 Web 部件呈现您的 HTML 和 JavaScript.
To use the above code, first save it to a text file and upload it to a library on your SharePoint site. Then you can then create a page on your site, add a content editor web part to the page, and edit the web part properties of that content editor web part. In the "Content Link" property, paste in the link to the text file; this will cause the web part to render your HTML and JavaScript.
如需进一步阅读,请查看 Common微软提供的 JavaScript 对象模型文档中的编程任务.
For further reading, check out the Common Programming Tasks in the JavaScript Object Model documentation provided by Microsoft.
这篇关于如何限制可在 SharePoint 列表中输入的项目数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!