[英]SPServices GetListItems function within another GetListItems function
我正在一個項目中,該項目在同一SharePoint網站中涉及兩個單獨的列表。 我已經在SPServices中使用GetListItems函數從列表A中檢索列表項,並將特定字段中的值插入到HTML字符串中以顯示在頁面上。
我還有第二個列表,列表B,我也希望能夠使用GetList Items進行查詢,但要基於第一個查詢的結果。
列表B包含一個基於列表B的ID列的查找列。因此兩者應共享一個公共數據點。 我想做的是能夠單擊從列表A返回的項之一-並基於查找列查看列表B中與其相關的項。
我知道這可能更多是Javascript問題,而不是SPServices問題,但是由於GetListItems函數的特定用法,我不確定從哪里開始。 誰能給我任何有關如何實現這一目標的見解?
謝謝。
以下代碼使用SPPlus使生活更輕松:
目的:從列表A中獲取項目,然后為列表A中的每個項目找出具有相同標題的列表B中存在多少項。
<head>
<script src="https://cdn.jsdelivr.net/npm/sharepointplus@5.1.0/sharepointplus-5.1.min.js"></script>
<script type="text/javascript" src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script>
$(document).ready(function () {
ExecuteOrDelayUntilScriptLoaded(onLoad(listA, listB), "sp.js");
});
function onLoad(listA, listB) {
$SP().list(listA).get({
fields: "Title",
}).then(function (response) {
var obj = {};
var dataA = response;
dataA.forEach(rowA => {
let titleFromListA = rowA.getAttribute("Title");
$SP().list(listB).get({
fields: "Title",
where: "Title='" + titleFromListA + "'"
}).then(function (response) {
let dataB = response;
let countofResultFromB = dataB.length;
obj[titleFromListA] = countofResultFromB;
})
});
console.log(obj)
})
}
</script> </head>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.