我有兩個下拉列表,這些列表使用PHP從數據庫動態填充。它們包含指定列的所有值,例如其中包含parameterType的所有值和dateTimeTaken的其他所有值。基於已篩選的D3.js數據禁用/啓用下拉列表選項
有什麼辦法可以禁用這些選項時,數據被過濾,其中一些選項可能不再適用 - 基本上我問是否動態填充下拉列表可以更新數據時,如果是這樣,這可以如何實現?
UPDATE:
我的數據是在以下格式:
[{"dateTimeTaken":"2013-01-01 14:05:14",
"reading":"0.90000",
"parameterType":"Flouride",
"inspectionPoint_id":"2"}....
,我已經試圖做到這一點使用下面的代碼 - 而不是做什麼?
d3.json("HistoricData.php", function(error,data)
{
var filtered_data = data.filter(function(d) { return d.inspectionPoint_id == i;})
filtered_data.forEach(function(d) {
d.dateTimeTaken = parseDate(d.dateTimeTaken);
d.reading = +d.reading;
d.parameterType = d.parameterType;
d.inspectionPoint_id = +d.inspectionPoint_id;
});
var check = d3.select("selectparameter")//select dropdown list
check.selectAll("option").each(checkOption);//select all options
//for any of the options that don't match the parameterType's
//from the filtered dataset set display to none
var checkOption = function (d, e) {
if(e !== d.values(d.parameterType)){
return d3.select(this).attr("display", "none");
}
};
UPDATE 2
d3.select("#selectparameter")
.append("select")
.selectAll("option")
.data(filtered_data)
.enter().append("option")
.text(function(d) { return d.parameterType; })
這可能是有幫助的:http://stackoverflow.com/questions/13097923/how-can-i-use-d3-or-just-javascript-to-set-a-form-option- as-being-selected- – 2013-03-17 14:57:18
謝謝你 - 這告訴我,有可能但不知道如何實現我所需要的。我已經嘗試過了 - 請參閱上面的更新。 – Newbie 2013-03-17 16:10:12