我使用可拖动的高图来描绘一些NBA工资单数据。如果栏被拖动,我想用新工资更改输入框。我已经有一段时间了,并没有取得多大进展。我可以获得一个可拖动的事件来更改输入框,但我不能反过来。我需要一些帮助。
我最初开始采用州改变路线,这是我的想法。基本上,图表可以控制全局,输入可以控制全局。然后我只需要更新DOM中的相应项目。
var state = {};
state.contractStructure = 'EQUAL'; // Could also be PROGRESSIVE, BACKEND, DIMINISHING
state.netIncome = <%= @team1_tax[:net_income] %>;
state.numYears = <%= @lookup_hash[:years]; %>;
state.incomeByYear = [];
function setNetIncome(value) {
state.netIncome = value;
if (state.contractStructure === 'EQUAL') {
var perYearIncome = state.netIncome / numYears;
for (var i = 0; i < state.numYears; i++) {
state.incomeByYear[i] = perYearIncome
}
} else if (state.contractStructure === PROGRESSIVE) {
}
// Once all data is computed.
// Loop through all input boxes and set input[i].value = state.incomeByYear[i]
}
Array.prototype.slice.call(document.getElementsByClassName('year-inputs')).forEach(element) {
element.addEventListener('change', function(e) {
var value = e.value; // this is the number typed intot he boxes
var i = ??? //
state.incomeByYear[i] = value
// Once all data computed
// Re-reneder the high chart with computed data
}
})
function onNewContractDrag(newValue, year) {
state.incomeByYear[year] = newValue
state.netIncome // somehow adjust according to newValue
// Need to update all boxes to reflect chagne in state
// Loop through each one. Each one's value get set to state.incomeByYear[i]
}
然后它似乎有点矫枉过正,所以我开始调查其他方式。
我已经创建了一个JsFiddle,但我只能从拖动到输入框。我应该去州改变路线吗? JsFiddle路线。