我有 3 个图书馆,我想显示图书馆项目名称。如果我只想显示一个图书馆的项目,一切都很好,但如果我正在寻找两个或更多图书馆的项目,它仍然只显示一个图书馆的项目。我的代码有什么问题?
<p id="AInfo">library A Items</p>
<p id="BInfo">library B Items</p>
<p id="CInfo">library C Items</p>
<script type="text/javascript">
jQuery(document).ready(function(){ExecuteOrDelayUntilScriptLoaded(fill, "sp.js"); });
var siteUrl = '/Example/test/';
liblist = new Array("A", "B", "C"); //list of the libraries
var i=0;
var lib;
function fill(){
while (i<3){
lib = liblist[i];
alert(lib);
retrieveListItemsInclude();
i++;
}
}
function retrieveListItemsInclude() {
var clientContext = new SP.ClientContext(siteUrl);
var oList = clientContext.get_web().get_lists().getByTitle(lib);
var camlQuery = new SP.CamlQuery();
camlQuery.set_viewXml('<View><RowLimit>100</RowLimit></View>');
this.collListItem = oList.getItems(camlQuery);
clientContext.load(collListItem, 'Include(Id, DisplayName, HasUniqueRoleAssignments)');
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 += oListItem.get_displayName()+ '<br>';
}
var x = listItemInfo.toString();
document.getElementById(lib+"Info").innerHTML = x;
}
function onQueryFailed(sender, args) {
var x = 'Request failed. ' + args.get_message() + '\n' + args.get_stackTrace();
document.getElementById(lib+"Info").innerHTML = x;
}
</script>