var context = SP.ClientContext.get_current();
var user = context.get_web().get_currentUser();
var collListItem = "";
var listItemEnumerator = "";
var listItemInfo = "";
var url = "/sites/Develop/ChildOne";
$(document).ready(function () {
retrieveListItems(url);
});
function retrieveListItems(siteUrl) {
var clientContext = new SP.ClientContext(siteUrl);
var oWebSite = clientContext.get_web();
var oList = oWebSite.get_lists().getByTitle("MyList");
var camlQuery = new SP.CamlQuery();
collListItem = oList.getItems(camlQuery);
clientContext.load(collListItem);
clientContext.executeQueryAsync(onQuerySucceeded,onQueryFailed);
}
function onQuerySucceeded(sender, args) {
listItemEnumerator = collListItem.getEnumerator();
while (listItemEnumerator.moveNext()) {
var oListItem = listItemEnumerator.get_current();
listItemInfo += "\nID: " + oListItem.get_id() +
"<br/>"+"姓名: " + oListItem.get_item("Name") +
"<br/>"+"身高: " + oListItem.get_item("Height") +
"<br/>"+"年龄:" + oListItem.get_item("Age")+"<br/>";
}
alert(listItemInfo);
}
function onQueryFailed(sender, args) {
alert('Request failed. ' + args.get_message() +
'\n' + args.get_stackTrace());
}
错误提示说,属性或字段尚未初始化。 但不知道是哪没初始化。onQuerySucceeded方法和onQueryFailed方法都没有执行