You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Why must 'to.(str)' be added to 'value'? Otherwise, an error will be reported:
'TypeError: Invalid var passed for prop TextFieldRoot.value, expected type str | int | float, got value item["test"] of type list[dict].'
If var does not contain a 'list': [{'a ':'A'}] There is no such problem
Why can't the value of input simply use item['test']?
class state(rx.State): var: list[dict[str, list[dict]]] = [ { 'test': 'test', 'list': [{'a': 'A'}] # It will cause some strange effects } ] def foreach_component(item: dict) -> rx.Component: return rx.el.input(value=item['test'].to(str)) # Only by adding. to(str) can it run here, why? def main() -> rx.Component: return rx.foreach(state.var, foreach_component)
中文:
为什么value必须加上to(str)?否则会报错:TypeError: Invalid var passed for prop TextFieldRoot.value, expected type str | int | float, got value item["test"] of type list[dict].
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
class state(rx.State): var: list[dict[str, list[dict]]] = [ { 'test': 'test', 'list': [{'a': 'A'}] # It will cause some strange effects } ] def foreach_component(item: dict) -> rx.Component: return rx.el.input(value=item['test'].to(str)) # Only by adding. to(str) can it run here, why? def main() -> rx.Component: return rx.foreach(state.var, foreach_component)中文:
class state(rx.State):
var: list[dict[str, list[dict]]] = [
{
'test': 'test',
'list': [{'a': 'A'}] # 它会造成一些奇怪的影响
}
]
def foreach_component(item: dict) -> rx.Component:
return rx.el.input(value=item['test'].to(str)) # 这里只有加上.to(str)可以运行,为什么?
def main() -> rx.Component:
return rx.foreach(state.var, foreach_component)
Beta Was this translation helpful? Give feedback.
All reactions