我正在尝试使用js将列表链接到sharepoint网站,列表是Utilities Contract,我想从该列表中恢复特定列

时间:2022-11-05 21:45:26

I am trying to link a list to a sharepoint website using javascript, the list is called 'Utilities Contract' and I want to bring back specific columns from that list. This is the code I have so far.

我正在尝试使用javascript将列表链接到sharepoint网站,该列表称为“公用事业合同”,我想从该列表中恢复特定列。这是我到目前为止的代码。

function retrieveSpecificListProperties(siteUrl) {
    var clientContext = new SP.ClientContext(siteUrl);
    var oWebsite = clientContext.get_web();
    this.collList = oWebsite.get_lists();

    clientContext.load(collList, 'Include(Title, Id)');
    clientContext.executeQueryAsync(
        Function.createDelegate(this, this.onQuerySucceeded), 
        Function.createDelegate(this, this.onQueryFailed)
    );
}

function onQuerySucceeded() {
    var listInfo = '';
    var listEnumerator = collList.getEnumerator();

    while (listEnumerator.moveNext()) {
        var oList = listEnumerator.get_current();
        listInfo += 'Title: ' + oList.get_title() + 
            ' ID: ' + oList.get_id().toString() + '\n';
    }
    alert(listInfo);
}

function onQueryFailed(sender, args) {
    alert('Request failed. ' + args.get_message() + 
        '\n' + args.get_stackTrace());
}

1 个解决方案

#1


0  

You can use the below mentioned code to get that data:

您可以使用下面提到的代码来获取该数据:

var clientContext = new SP.ClientContext();

var oList = clientContext.get_web().get_lists().getByTitle('Utilities Contract');

var camlQuery = new SP.CamlQuery();

var collListItem = oList.getItems(camlQuery);

clientContext.load(collListItem);

clientContext.executeQueryAsync( 
    function(){
        var listItemEnumerator = collListItem.getEnumerator();
        while (listItemEnumerator.moveNext()) {

            var oListItem = listItemEnumerator.get_current();

            var itemTitle = oListItem.get_item('Title');

            var itemId = oListItem.get_id();
    },
    function(sender, args){
        console.log('Request failed. ' + args.get_message() + 
        '\n' + args.get_stackTrace());
});

More exhaustive samples - How to: Retrieve List Items Using JavaScript

更详尽的示例 - 如何:使用JavaScript检索列表项

#1


0  

You can use the below mentioned code to get that data:

您可以使用下面提到的代码来获取该数据:

var clientContext = new SP.ClientContext();

var oList = clientContext.get_web().get_lists().getByTitle('Utilities Contract');

var camlQuery = new SP.CamlQuery();

var collListItem = oList.getItems(camlQuery);

clientContext.load(collListItem);

clientContext.executeQueryAsync( 
    function(){
        var listItemEnumerator = collListItem.getEnumerator();
        while (listItemEnumerator.moveNext()) {

            var oListItem = listItemEnumerator.get_current();

            var itemTitle = oListItem.get_item('Title');

            var itemId = oListItem.get_id();
    },
    function(sender, args){
        console.log('Request failed. ' + args.get_message() + 
        '\n' + args.get_stackTrace());
});

More exhaustive samples - How to: Retrieve List Items Using JavaScript

更详尽的示例 - 如何:使用JavaScript检索列表项