问题描述
我正在尝试使用Vimeo的oEmbed将多个视频嵌入到网页中。想法是,只需在CMS中输入网址,即可为包含以下代码的每个项目生成一个div。
此javascript可以满足我的要求,但仅适用于第一项。当我检查控制台时,只有一个响应包含第一个项目/视频的JSON元数据。
这可能不是最好的方法,但是可以完成工作,我所要做的就是使它适用于多个项目。有什么想法我该怎么做?
谢谢
# Load required R packages
library(highcharter)
# Set highcharter options
options(highcharter.theme = hc_theme_smpl(tooltip = list(valueDecimals = 2)))
df <- data.frame(Year=c('2015','2016','2017','2018','2019'),CD=c(24,18,12,9,14))
head(df)
hc <- df %>%
hchart('column',hcaes(x = Year,y = CD),color = "#702080",borderColor = "#702080",pointWidth = 80) %>%
hc_title(text = "Critical Days") %>%
hc_xAxis(categories = 'Critical Days') %>%
hc
解决方法
如果像我这样具有基本JavaScript技能的人经历了类似的事情。问题是菜鸟的错误,我不得不使用var
而不是const
。
原因是因为var
变量可以被更新和重新声明,而const变量既不能被更新也不能被重新声明。所以这是工作代码:
var getJSON = async (url) => {
try {
var response = await fetch(url);
if (!response.ok)
// check if response worked (no 404 errors etc...)
throw new Error(response.statusText);
var data = await response.json(); // get JSON from the response
return data; // returns a promise,which resolves to this data value
} catch (error) {
return error;
}
};