你能用这个脚本帮助我吗?我试图从列表'faq'中提取数据并获得输出警报但不使用CAML查询。但我没有得到输出。请帮忙。
No. of Invoices = CALCULATE(DISTINCTCOUNT(InvNumber), FILTER(Table_Name, 'Table_Name'[OrderType] = "Sales"))
答案 0 :(得分:0)
使用REST API代码获取SharePoint列表项的最佳方法如下。
ExecuteOrDelayUntilScriptLoaded(initializePage, "sp.js");
function initializePage() {
var siteURL;
var itemsArray = [];
// This code runs when the DOM is ready and creates a context object which is needed to use the SharePoint object model
$(document).ready(function() {
var scriptbase = _spPageContextInfo.webServerRelativeUrl + "/_layouts/15/";
GetSampleListItems();
});
//Retrieve list items from sharepoint using API
function GetSampleListItems() {
siteURL = _spPageContextInfo.siteAbsoluteUrl;
console.log("from top nav - " + siteURL);
var apiPath = siteURL + "/_api/lists/getbytitle(''samplelist'')/items";
$.ajax({
url: apiPath,
headers: {
Accept: "application/json;odata=verbose"
},
async: false,
success: function(data) {
var items; // Data will have user object
var results;
if (data != null) {
items = data.d;
if (items != null) {
results = items.results
for (var i = 0; i < results.length; i++) {
itemsArray.push({
"Title": results[i].Title
});
}
}
}
},
eror: function(data) {
console.log("An error occurred. Please try again.");
}
});
}
}
使用REST API,请找到以下代码。
var siteUrl = 'SiteCollection';//HEre you need to give your site collection URL
function retrieveAllListItems() {
var clientContext = new SP.ClientContext(siteUrl);//Will return current context
var oWebsite = clientContext.get_web();//Curent site
this.collList = oWebsite.get_lists();//Liist
clientContext.load(collList);
clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));
}
//
function onQuerySucceeded() {
var listInfo = '';
//Below is the iteration for item
var listEnumerator = collList.getEnumerator();
while (listEnumerator.moveNext()) {
var oList = listEnumerator.get_current();
listInfo += 'Title: ' + oList.get_title() + ' Created: ' + oList.get_created().toString() + '\n';
}
alert(listInfo);
}
function onQueryFailed(sender, args)
//this will fire when you will any failure in your code..means in your Success method..
}
有很多好的博客Plz找到下面的一个
http://msdn.microsoft.com/en-us/library/hh185009%28v=office.14%29.aspx
如果您正在寻找其他任何更新我的信息。