我正在使用面向物件的圖表并根據滾動位置設定資料。我正在使用 d3.csv() 通過 then() 加載資料,如下所示:
const chart = new Chart(instatiatechartfunctions);
let dataObj1 = d3.csv('datapath', dataparsefunction);
let dataObj2 = d3.csv('datapath2', dataparsefunction);
let dataArr = [dataObj1,dataObj2];
function init(data){
chart.setData(data);
}
let g3 = scrollerfunction().settings()
.on('active', function(i){
dataArr[i].then(init); //error here
});
包含滾動庫和圖表的所有代碼對我來說非常復雜,所以我希望以上內容足夠清楚。我的主要問題是init在then()沒有 () 的情況下呼叫會顯示圖表,但會回傳標題中的錯誤。當我使用括號 ( then(init())) 時,出現以下錯誤:
Uncaught TypeError: Cannot read properties of undefined (reading '0')
我正在使用 d3.v6 誰能幫忙?
uj5u.com熱心網友回復:
把.then(init)沒有括號是等于說.then((array) => init(array)),在這兩種情況下,你是給.then一個引數的函式,在你的承諾的回報率執行。如果錯誤隨后出現在標題中,我猜是代碼的那部分發生了一些事情,但不是這里。
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/403551.html
標籤:
