簡體   English   中英

帶有數據作為參數的 D3Js 按鈕 onclick 在 .html() 中不起作用

[英]D3Js button onclick with data as parameter doesnt work in .html()

我想要我的按鈕,它是在 D3Js 中通過.html 創建的,可以調用fillTable function 並將其作為參數提供 d(數據)。 問題是,在我下面的例子中,我得到Uncaught ReferenceError: d is not defined

           d3.select("#test")
                    .selectAll("div")
                    .data(myData)
                    .enter().append("div")
                    .attr("class", "process")
                    .html(function (d, i) {
                        if (typeof d === 'object') {
                            console.log(d);
                            let processHtml = "<button title='Process settings' onclick = 'fillTable(d)' class='btn'></button>"
                         }
                   return processHtml
                     )}


function fillTable(data) {
   console.log(data)
}

我已經嘗試將 processHTML 更改為:

let processHtml = "<button title='Process settings' onclick = 'process.fillComponentTable('" + d + "')' class='btn'></button>"

結果是:

Uncaught SyntaxError: expected expression, got '}'

我怎樣才能解決這個問題?

fillTable(" + JSON.stringify(d) + ")'

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM