【发布时间】:2019-05-16 02:02:00
【问题描述】:
我希望能够在 CustomJS 回调中引用 2 Select 小部件(select1.value 和 select2.value),所以我不能使用 cb_obj.value。
select1 = Select(title="Level:", options=['All Levels', '1', '2', '3'], callback=callback)
首先,我尝试在回调中直接引用它的值:
callback = CustomJS(args=dict(source=source, ts=true_source), code="""
var f = select1.value
这导致错误:select1 未定义:
Uncaught ReferenceError: select1 is not defined
at eval (eval at get (bokeh-1.1.0.min.js:31), <anonymous>:9:11)
at i.execute (bokeh-1.1.0.min.js:31)
at e.change_input (bokeh-widgets-1.1.0.min.js:31)
at e.change_input (bokeh-widgets-1.1.0.min.js:31)
at HTMLSelectElement.<anonymous> (bokeh-widgets-1.1.0.min.js:31)
然后我尝试将select1 传递给回调中的参数:
callback = CustomJS(args=dict(source=source, ts=true_source, select1=select1), code="""
var f = select1.value
因为select1的参数是callback=callback,如果我在定义callback之前定义select1,python会产生错误,因为callback在赋值之前被引用。如果我在选择小部件之前定义callback,反之亦然。
所以我尝试了这个:定义select1 两次
select1 = ... (without the callback argument)
callback = ...
select1 = ... (with the callback argument)
这最终生成了散景图。但是当我点击选择小部件时,没有任何价值。
var f=select1.value;
console.log('Select1 type ' + f.constructor.name.toLowerCase()); // string, as expected
console.log('Value ' + f); // outputs 'Value ', so f is nothing
console.log('Select1 options ' + select1.options); // Output is as expected
如果我向select1 提供默认值参数,select1.value 将不为空:
select1 = Select(title="Level:", value='1', options=['All Levels', '1', '2', '3'], callback=callback)
但是,无论我将小部件的实际值更改为什么,select1.value 都将保持为“1”。所以值根本没有更新。
感谢您的帮助.. 谢谢!
【问题讨论】:
标签: javascript python pandas bokeh