ajax - 如何使用从 AJAX 获取 API 调用的 JSON 结果的参数调用另一个函数
问题描述
我必须使用 JSON 结果从此函数中获取 ParentId,然后在此函数之后调用下面给出的另一个函数:
public fetchLibraryDatafromSharePointList(clientID:string) {
debugger;
const reactHandler = this;
jquery.ajax({
url: `${this.props.siteurl}/_api/web/lists/getbytitle('MSAs')/items?$filter=ClientID eq '${clientID}'&$orderby=Modified desc`,
type: "GET",
headers:{'Accept': 'application/json; odata=verbose;'},
success: function(resultData2) {
reactHandler.setState({
items: resultData2.d.results
});
},
error : function(jqXHR, textStatus, errorThrown) {
}
});
}
以下是上述 API 成功后必须调用的函数,参数来自上一次调用的 JSON 结果:-
SetState 由 reactHandler 变量完成
public fetchDatafromSharePointList(ParentID) {
debugger;
const reactHandler = this;
jquery.ajax({
url:`${this.props.siteurl}/_api/web/lists/getbytitle('MSASummaries')/items?
$filter=Parent eq ${ParentID}$top=1&$orderby=Modified desc`,
type: "GET",
headers:{'Accept': 'application/json; odata=verbose;'},
success: function(resultData) {
/*resultData.d.results;*/
reactHandler.setState({
items: resultData.d.results
});
},
error : function(jqXHR, textStatus, errorThrown) {
}
});
}
解决方案
fetchLibraryDatafromSharePointList(clientID:string)
您可以在更新状态后的成功响应中调用另一个函数。IE:
reactHandler.setState({
items: resultData2.d.results
}, ()=>{
fetchDatafromSharePointList(your_parent_id_goes_here);
});
推荐阅读
- tensorflow - Does tensorflow allow LSTM deconvolution ( convlstm2d) as it does for 2D convolution?
- java - 获取pdf中页眉页脚的位置
- c - Tournament scheduling table C algorithm
- c# - concurrent access of list in c#
- python - How do I parse a yaml string with python?
- sql - 我们可以在 SQL Server 中为每个计数使用多个计数(列)和 where cluase
- python - 我如何删除 python 2.7,因为我已经在 ubuntu 上安装了 3.6.5?
- go - 如何避免在连续错误处理中重复自己
- python - 如何调试通过 Jenkins 运行 shell 脚本的问题?
- csom - 如何通过 csom 代码使用保存的模板创建任务列表