簡體   English   中英

如何使用javascript從Sharepoint列表中獲取值

[英]how to get a value from a Sharepoint list with javascript

我有以下代碼:

window.onload = function () {
    var setTime = /*this should go the number*/
    var fiveMinutes = 60 * setTime;
        display = document.querySelector('#timer2');
    startTimer(fiveMinutes, display);
};

我想是var setTime來獲取值或從列表中有一個名為列中檢索testval數據類型為testval的感謝所有的號碼!

如果是像這樣的td元素<td name="testval">15</td>

window.onload = function () {
   var testval = document.getElementsByName('testval')[0]; // if it's the first elem with this name
   //var testval = $('td[name=testval]'); // jquery
   var setTime = parseInt(testval.innerHTML); // 15
   var fiveMinutes = 60 * setTime;

   display = document.querySelector('#timer2');
   startTimer(fiveMinutes, display);
};

jsFiddle為您-http: //jsfiddle.net/y02os529/

要與SharePoint通信,您需要使用JavaScript客戶端對象模型,如下所示:

 var ctx = new SP.ClientContext.get_current();
 var web = ctx.get_web();
 var listCollection = web.get_lists();
 var list = listCollection.getByTitle(NameOfYourList);
 var listItem = list.getItemById(TheItemID);
 context.load(listItem);

 context.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));

接着

 function onQuerySucceeded() {
 var setTime =  listItem.get_item('testval');
 //continue your work
}

 function onQueryFailed(sender, args) {
 alert('failed');
}

記住要引用SP.js腳本標記:

 <SharePoint:ScriptLink Name="SP.js" runat="server" OnDemand="true" Localizable="false" ></SharePoint:ScriptLink>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

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