javascript - 如何将 api 调用中的元素列表附加到无序列表?
问题描述
我正在尝试从请求中创建元素列表并将这些元素附加到现有的无序列表中。这是检索 json 并做一个小过滤器的调用
let authorizedSystems;
let isPortal;
const portalUrls = [
"http://portal-dev.com",
"https://portal-alpha.com",
"https://portal-beta.com",
"https://portal-sandbox.com",
"https://portal.com"
]
const fetchAuthSystems = axios.get('/user-profile/api/user/authorized-systems')
.then(function(res) {
let portals = res.data.authorizedSystems;
return portals;
})
.catch(function(e) {
})
const fetchAuthResults = function() {
fetchAuthSystems.then(function(portals) {
authorizedSystems = portals;
const filteredPortals = authorizedSystems.filter(function(system) {
return system.label !== isPortal;
})
return filteredPortals;
})
.then(function(systems) {
const newList = systems.map(function(system) {
return "<a href=" + url + " target='_blank' class='portalLink'><li class='openSiteLinkAnchor'></li>" + system.label + "</a>";
})
return newList;
})
}
fetchAuthResults();
我上面所做的就是从 api 调用中获取数据,进行过滤并创建一个列表。这是我的html:
const html = "<div id='portalLinkContainer'>" +
"<ul class='openSite'><i class='fa fa-chevron-down openSiteIcon'></i> Open related site" +
"</ul>" +
"</div>"
理想情况下,我想做的是使用新列表并将其设置为授权系统的值,然后能够稍后将其附加到我拥有的 html 中的 ul 中。
解决方案
推荐阅读
- javascript - Gatsby & React Context API:使用 Context 设置语言以实现国际化
- angular - 将 Observable 转换为 Promise 的任何不利因素
- python - 如何计算熊猫一周中每天最大值的最常见时间
- javascript - Github API“参考已经存在/StatusCode:409”创建或更新文件内容
- django - 将变量传递给标记 django
- php - 如何使用 PHP 提取特定的 JSON 元素?
- kubernetes - 有没有办法阻止特使添加特定的标头?
- c++ - 这些浮点属性宏是 GCC 特有的吗?
- swift - Swift 数组地址与 &array[0] 不同
- matlab - matlab中的符号模运算