我正在尝试获取按钮单击时组合框的值,并在按钮单击处理程序中处理该值。但是,combobox_v_model似乎只有在按钮单击处理程序退出后才被正确更新。
以下是我所做的(代码如下(:
- 当窗口小部件出现时,在组合框中输入字符串"xxx">
- 然后单击按钮,获取combobox.v-model的值
- 应检索"xxx",但检索到的却是"(空字符串(
有没有一种方法可以在输入后立即点击按钮来检索组合框内容?
注意:当在单击按钮之前按下"Enter"/"TAB"时,一切都会起作用,但如果在组合框中输入后立即按下按钮,则不会起作用。
import ipyvuetify as vue
name = ''
# vuetify combobox and button
combobox = vue.Combobox(label="Enter name", v_model="", items=[], autofocus=True)
btn = vue.Btn(children=['Process name'])
component = vue.Row(children=[
vue.Col(children=[combobox]),
vue.Col(children=[btn])
])
# --- event handler -------------------------
# Some processing of the combobox input needs to happen
# on a button click, but v_model is not updated
def on_button_clicked(widget, event, data):
print(f"btn clicked: {combobox.v_model=}")
name = combobox.v_model
print(f'btn clicked: {name=}')
# do some processing with name here
btn.on_event("click", on_button_clicked)
display(component)
可能是Vuetify中的一个错误:vuetifyjs/Vuetify#12567(也可以参考ipyvutify问题跟踪器上的这篇文章(。