无法使我的输入栏对我的用户回调不区分大小写

Cannot make my input bar case-insensitive for my user callback

我在我的应用程序中使用破折号。我的应用程序的一部分有一个多输入栏,用户可以在其中快速搜索值并 select 它们。唯一的问题是,输入栏区分大小写。搜索 nflxNFLX 的用户将得到两个不同的结果,其中只有一个是正确的并且有效。我需要两个值都匹配。

我只解决了用户输入的第一个值的问题!由于我的功能,只有用户输入的第一个值在设计上不区分大小写。因为我的输入 value 有时可以是一个值(字符串)或多值(列表),所以我正在努力尝试对通过回调

输入和传递的所有值实现不区分大小写

我需要尽快删除它并且我一直在尝试弄清楚如何使用 Dash 的回调(基于 Flasks 回调)。

@app.callback(
    dash.dependencies.Output("dynamic-dropdown", "options"),
    [dash.dependencies.Input("dynamic-dropdown", "search_value")],
    [dash.dependencies.State("dynamic-dropdown", "value")],
)
def update_multi_options(search_value, value):
    if search_value is None:
        raise PreventUpdate
    elif search_value is True:
        search_value.upper()

    elif value is None:
        raise PreventUpdate
    elif search_value is None:
        raise PreventUpdate
    elif value is list:
        [x.upper() for x in value]
        [x.upper() for x in search_value]
        
        return [
            o for o in OPTIONS if search_value in o["label"] or o["value"] in (value.upper() if value else [])
        ]
    else:
    # Make sure that the set values are in the option list, else they will disappear
    # from the shown select list, but still part of the `value`.
        [x.upper() for x in value]
        [x.upper() for x in search_value]
        return [
            o for o in OPTIONS if search_value in o["label"] or o["value"] in (value or [])
        ]

是的,我在调试过程中过度使用它,试图找出我的错误。目标是尝试玩 valuesearch_value。没有一个简单的函数可以做到这一点,因为列表没有 .upper()

的属性

提前感谢您的指导。

使用此函数我没有收到任何 TraceBack 错误。

了解如何解决以下问题:

@app.callback(
    dash.dependencies.Output("dynamic-dropdown", "options"),
    [dash.dependencies.Input("dynamic-dropdown", "search_value")],
    [dash.dependencies.State("dynamic-dropdown", "value")],
)
def update_multi_options(search_value, value):
    if search_value is None:
        raise PreventUpdate
    else:
    # Make sure that the set values are in the option list, else they will disappear
    # from the shown select list, but still part of the `value`.
        return [
            o for o in OPTIONS if search_value.upper() in o["label"].upper() or o["value"] in (value or [])
        ]

您只需关注 search_valueo["label"] 即可添加 upper()