Can a ui.input value be bound to a list element? #4147
-
QuestionI am trying to bind (both ways) the value of a ui.input() to an element of a python list. I understand how to bind "from" the list element using backward=lambda v: v[1], but can't figure out how to bind the input's value "to" the list element. I think I would need to use the "forward" parameter in the bind_value() call, but don't know what to put in there to make it work. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
I don't think it's possible directly. You could whip up a convoluted solution using a custom helper class or a Can you change your data structure to be a dict instead of a list? That would be a cleaner solution. If not, perhaps you can change your list to an index. Instead of mydict = { 'foo' : 'abc', 'bar' : 'def'}
mylist = list (mydict)
# accessing values
value = mydict [ mylist [0] ]
# binding
ui.input ().bind_value (target_object = mydict, target_name = mylist [0]) |
Beta Was this translation helpful? Give feedback.
I don't think it's possible directly.
bind_value_to
needs a reference to bind to, given as object ref and property name (string). When updating value, it does something likeobject.setattr (name, newvalue)
internally. I'm not aware of a way to access list items by a string name - that's what a dict does.You could whip up a convoluted solution using a custom helper class or a
UserList
that takes a key name and gets / sets a specified item in the list. But not a good idea. At that point you're just reinventing a dict poorly.Can you change your data structure to be a dict instead of a list? That would be a cleaner solution.
If not, perhaps you can change your list to an index. Instead of
m…