簡體   English   中英

Sharepoint文檔庫-使用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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM