JavaScript SHAREPOINT 2010使用ECMASCRIPT从列表中读取

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了JavaScript SHAREPOINT 2010使用ECMASCRIPT从列表中读取相关的知识,希望对你有一定的参考价值。

<script type="text/javascript">   

ExecuteOrDelayUntilScriptLoaded(functionName, "sp.js");   //this is necessary to ensure the library is loaded before function triggered
 var namedListItem;  


function functionName() {


var clientContext = SP.ClientContext.get_current();
//or use the syntax below for accessing a list that may not reside in the current site
//var clientContext = new SP.ClientContext(rootUrl);

var myList = clientContext.get_web().get_lists().getByTitle('myList'); //actual list name here

var camlQuery = new SP.CamlQuery();
camlQuery.set_viewXml(''); //caml statement goes here between the single quotes
namedListItem = myList.getItems(camlQuery);
        
   clientContext.load(namedListItem);
   //or use below to specify to load only the required properties for better performance
   //clientContext.load(namedListItem, 'Include(field1, field2)');
        
   clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));
}

function onQuerySucceeded(sender, args) {

    var listItemInfo = '';

    var listItemEnumerator = namedListItem.getEnumerator();
        
    while (listItemEnumerator.moveNext()) {
        var oListItem = listItemEnumerator.get_current();
        listItemInfo +=  '\nField1: ' + oListItem.get_item('field1') +    ', Field2: ' + oListItem.get_item(' field2'); //replace field1 & field2 with actual column names
    }

    alert(listItemInfo.toString());
}

function onQueryFailed(sender, args) {

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

</script>

以上是关于JavaScript SHAREPOINT 2010使用ECMASCRIPT从列表中读取的主要内容,如果未能解决你的问题,请参考以下文章

SharePoint 2013 使用 JavaScript 获取当前用户

JavaScript sharepoint绝对网站集URL javascript变量

如何从SharePoint列表创建javascript数组?

使用 JavaScript 更改 SharePoint 列上的下拉选项值

Sharepoint 2010 在 jquery/javascript 中捕获 webpart 刷新

javascript 获取SharePoint 2010/2013 userID