![](/img/trans.png)
[英]Create a copy of document in SharePoint 2010 document library using JavaScript
[英]Sharepoint Document Library - Filename to title using javascript
晚上好!
我在sharepoint文档库上有一个工作功能。 目的是将文件名复制到标题列。
它已经工作了很长时间,但是在对SharePoint平台进行更新之后,它停止工作了,我不知道为什么。
编码:
<input type="button" onclick="updateTitleFromName()" value="Update Title from Name" />
<script type="text/javascript" src="/Scripts/jquery-1.10.2.min.js"></script>
<script type="text/javascript" src="/Scripts/spjs-utility/spjs-utility.js"></script>
<script type="text/javascript">
function updateTitleFromName(){
var q, res, uRes, count;
count = 0;
q = "<Where><IsNull><FieldRef Name='Title' /></IsNull></Where>";
res = spjs_QueryItems({"listName":_spPageContextInfo.pageListId,"query":q,"viewFields":["ID","FileLeafRef"]});
if(res.count === 0){
alert("No files without title found.");
return;
}
if(!confirm("There are "+res.count+" files to update. The page will appear as frozen while the script is working.\n\nContinue?")){
return;
}
$.each(res.items,function(i,item){
uRes = spjs_updateItem({"listName":_spPageContextInfo.pageListId,"id":item.ID,"data":{"Title":item.FileLeafRef.split(";#")[1]}});
if(!uRes.success){
alert("Could not update the file: "+item.FileLeafRef+" due to the follwing error:\n\n"+uRes.errorText);
}else{
count += 1;
}
});
alert("Updated "+count+" files.");
location.href = location.href;
}
</script>
错误是:TypeError:$ spjs为null。 它发生在spjs_QueryItems调用的spjs-utility库内部。
也许这可能是由于在更新过程中添加了一个冲突的库,但是我该如何调试呢?
另外,如果这行不通,用jQuery进行同样的操作会更简单吗? 那就是我现在正在尝试的内容,但是您一定已经意识到我是一个初学者。
提前致谢。
最好
我会测试你的updateTitleFromName函数中是否加载了JQuery:
if (window.jQuery) {
alert('loaded');
} else {
alert('not loaded');
}
如果未加载,请尝试使用绝对URL引用脚本以查看是否可以加载它们:
<script type="text/javascript" src="http://myportal/Scripts/jquery-1.10.2.min.js"></script>
<script type="text/javascript" src="http://myportal/Scripts/spjs-utility/spjs-utility.js"></script>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.