我能够在 Salesforce LWC 组件中可视化我的 D3 图表,但是现在我想要做的是,当我单击 D3 代码中的选定节点时,我想将选定的节点数据传递给 Salesforce 变量,然后我可以传递给我的子组件,它是一个模态。下面的代码显示了我当前在同一页面中将名称写入另一个 div 的位置,但是当我尝试从 Salesforce 变量中引用数据时,这对我没有帮助。
if (d.data.isProduct) {
thisNode.append("rect")
.attr("y", -barHeight / 2)
.attr("height", barHeight)
.attr("width", barWidth)
.style("fill", color)
.attr("class", "product " + d.data.modalName) // Add the select products modalName as a class to be used as a router to say what type of product fields to display
.on("click", function (d) {
// Only Run Logic when a Product is selected
if (d3.select(this).classed("product")) {
//var thisProductNode = d3.select(this);
// Only add product to the 'Selected Product' list if it was not already selected
if (!selectedProducts.includes(d.data.name)) {
selectedProducts.push(d.data.name); // Add selected product to list of selected products to be added to the product catalog
console.log('selected Products in Update: ' + JSON.stringify(selectedProducts, null, 2));
selectedProductsDisplay.append('ul').append('li').text(d.data.name);
}
// Toggle the slds-hide class of the modal depending on current value
// - shoppingCartModal is defined at the top of the initializeD3 function
shoppingCartModal.classed('slds-hide', shoppingCartModal.classed('slds-hide') ? false : true);
}
});
}