如何使用JavaScript从SharePoint列表中提取数据

时间:2014-02-11 12:25:11

标签: javascript sharepoint raphael extraction

我正在尝试从我的私有Sharepoint列表中提取数据,我的列表有3列:ID | PieCategory | PieNumber和12个值。我在开发中心here找到了这段代码。出于某种原因,即使看起来如此简单,也有些事情无效。我已经写过:

alert('Test');

这方面一切都很好,所以我的列表或下面的代码一定有问题。我并不特别喜欢这个代码,如果有更好/最简单的方法我会接受它!我已经尝试了下面写的其他代码而没有(使用当前的设置我已经写好了)。

var siteUrl = '/sites/MyPersonalSite';
function retrieveListItems() {
var clientContext = new SP.ClientContext(siteUrl);
var oList = clientContext.get_web().get_lists().getByTitle('pieChart'); 
//This is my list '/sites/MyPersonalSite/Lists/pieChart/AllItems.aspx'

var camlQuery = new SP.CamlQuery();
camlQuery.set_viewXml('<View><Query><Where><Geq><FieldRef Name=\'ID\'/>' + 
    '<Value Type=\'Number\'>1</Value></Geq></Where></Query><RowLimit>2</RowLimit></View>');
this.collListItem = oList.getItems(camlQuery);
// It was originally set to 10 but moved it to 2 and I have 12 observations so it should be enough

clientContext.load(collListItem);

clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));        
    }
function onQuerySucceeded(sender, args) {

var listItemInfo = '';

var listItemEnumerator = collListItem.getEnumerator();

while (listItemEnumerator.moveNext()) {
    var oListItem = listItemEnumerator.get_current();
    listItemInfo += '\nID: ' + oListItem.get_id() + 
        '\nCategory: ' + oListItem.get_item('PieCategory') + 
        '\nValue: ' + oListItem.get_item('PieNumber');
}

alert(listItemInfo.toString());
}
function onQueryFailed(sender, args) {

alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
}

我悲惨地试图实施的第二个守则。

function retrieveListItems() {

var clientContext = new SP.ClientContext('/sites/MyPersonalSite');
var oList = clientContext.get_web().get_lists().getByTitle('pieChart');

var camlQuery = new SP.CamlQuery();
camlQuery.set_viewXml('<View><Query><Where><Leq>' + 
    '<FieldRef Name=\'ID\'/><Value Type=\'Number\'>10</Value>' + 
    '</Leq></Where></Query><RowLimit>5</RowLimit></View>');

this.collListItem = oList.getItems(camlQuery);

clientContext.load(collListItem, 'Include(ID, PieNumber, PieCategory)');

clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));        
    }
function onQuerySucceeded(sender, args) {

var listItemInfo = '';

var listItemEnumerator = collListItem.getEnumerator();

while (listItemEnumerator.moveNext()) {
    var oListItem = listItemEnumerator.get_current();
    listItemInfo += '\nID: ' + oListItem.get_id() + 
        '\nDisplay name: ' + oListItem.get_PieNumber() +
        '\nCategory: ' +oListItem.get_PieCategory();
}

alert(listItemInfo.toString());
}

function onQueryFailed(sender, args) {

alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
}

我知道有很多方法可以通过C#实现这一点,但我只能在JavaScript上实现这一点,因为我正在尝试将其从gRaphael推广到一个Graph中,并且我试图让它非常简单以备将来使用。< / p>

0 个答案:

没有答案