【发布时间】:2020-02-04 19:43:52
【问题描述】:
我会用元素绑定数据
首先我选择我的元素
let trainSelect = svg.selectAll('.train-w-dir');
当我console.log(trainSelect) 时,我得到的元素不是空的
然后我绑定数据
trainSelect
.data(schedules, function(d: ISchedule) {
return d.train;
})
.enter()
.on('mouseover', tip.show)
.on('mouseout', tip.hide);
我在包含对象数组的调试器上检查计划。
但是在key函数里面didundefined我不明白为什么?
所以我收到错误Cannot read property 'train' of undefined
【问题讨论】:
-
你将
d重命名为ISchedule所以你应该这样做return ISchedule.train; -
我正在定义它的类型,因为没有
ISchedule我得到 TS 错误Property 'train' does not exist on type 'unknown' -
哦,原来你用的是 TS,之前没有标签所以是误导
标签: javascript typescript d3.js