gpt4 book ai didi

javascript - 使用 Javascript 显示共享点库项目

转载 作者:行者123 更新时间:2023-11-28 09:02:23 25 4
gpt4 key购买 nike

我有 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>

最佳答案

我认为您需要等待第一个请求完成后再执行第二个请求。类似的东西(但是代码很脏,因为你应该避免全局变量......)

<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 = liblist[i];
retrieveListItemsInclude();

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;
if (++i<3) {
lib = liblist[i];
retrieveListItemsInclude()
}
}


function onQueryFailed(sender, args) {

var x = 'Request failed. ' + args.get_message() + '\n' + args.get_stackTrace();
document.getElementById(lib+"Info").innerHTML = x;
}

</script>

关于javascript - 使用 Javascript 显示共享点库项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17549877/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com