Sharepoint JSCOM 列表操作

來源:互聯網
上載者:User

標籤:rand   cut   官方文檔   官方   cli   log   doc   point   ima   

  SP.SOD.executeFunc(‘sp.js‘, ‘SP.ClientContext‘, retrieveListItemsInclude); //確保js檔案載入,再執行方法    function retrieveListItemsInclude() {        var clientContext = new SP.ClientContext.get_current();        var oList = clientContext.get_web().get_lists().getByTitle(‘背景圖片‘);        var camlQuery = new SP.CamlQuery();        camlQuery.set_viewXml(‘<View><RowLimit>100</RowLimit></View>‘);        this.collListItem = oList.getItems(camlQuery);        clientContext.load(collListItem, ‘Include(ServerUrl)‘); //ServerUrl的路徑類似---/DocLib/123.jpg;        clientContext.executeQueryAsync(            Function.createDelegate(this, this.onQuerySucceeded),            Function.createDelegate(this, this.onQueryFailed)        );    }    
//成功回呼函數 function onQuerySucceeded(sender, args) { this.BackgroundImg = []; var listItemEnumerator = collListItem.getEnumerator(); while (listItemEnumerator.moveNext()) { var oListItem = listItemEnumerator.get_current();

/**這裡需要注意!對於某些屬性有內建的擷取方法,比如:get_id(),get_title();
*但對於大多數的屬性都必須使用get_item("屬性名稱")來擷取值,
**/而且”屬性名稱“要跟 Include("屬性名稱")中的屬性名稱保持大小寫一致!!

       this.BackgroundImg.push(oListItem.get_item("ServerUrl")); } if (this.BackgroundImg.length > 0) { var index = Math.floor((Math.random() * this.BackgroundImg.length)); //隨機數 $("#s4-workspace").css("background-image", "url(" + this.BackgroundImg[index] + ")"); } }
//失敗回呼函數 function onQueryFailed(sender, args) { alert(‘Request failed. ‘ + args.get_message() + ‘\n‘ + args.get_stackTrace()); }

要查看列表欄位的名稱(Title)和對應的內部名稱(InternalName),可以參考官方文檔:

function retrieveAllListsAllFields(siteUrl) {    var clientContext = new SP.ClientContext(siteUrl);    var oWebsite = clientContext.get_web();    var collList = oWebsite.get_lists();    this.listInfoArray = clientContext.loadQuery(collList,         ‘Include(Title,Fields.Include(Title,InternalName))‘);    clientContext.executeQueryAsync(        Function.createDelegate(this, this.onQuerySucceeded),         Function.createDelegate(this, this._onQueryFailed)    );}function onQuerySucceeded() {    var listInfo = ‘‘;    for (var i = 0; i < this.listInfoArray.length; i++) {        var oList = this.listInfoArray[i];        var collField = oList.get_fields();        var fieldEnumerator = collField.getEnumerator();                    while (fieldEnumerator.moveNext()) {            var oField = fieldEnumerator.get_current();            var regEx = new RegExp(‘name‘, ‘ig‘);                        if (regEx.test(oField.get_internalName())) {                listInfo += ‘\nList: ‘ + oList.get_title() +                     ‘\n\tField Title: ‘ + oField.get_title() +                     ‘\n\tField Name: ‘ + oField.get_internalName();            }        }    }    alert(listInfo);}function onQueryFailed(sender, args) {    alert(‘Request failed. ‘ + args.get_message() +         ‘\n‘ + args.get_stackTrace());}

 參考:https://msdn.microsoft.com/zh-cn/library/office/jj163201.aspx

Sharepoint JSCOM 列表操作

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.