Filtering Variables based on ForEach #5974
Replies: 1 comment
|
The failing index is the first one,
if not isinstance(key, (StringVar, str, int, NumberVar)) or (...):
raise_unsupported_operand_types("[]", (type(self), type(key)))
Either of these fixes it. 1. Cast the key (one-line change): def property_target_table(property_dict):
property_id = property_dict["id"].to(int)
...2. Give the list a real item type, so from typing import TypedDict
class Property(TypedDict):
id: int
name: str
class TargetWizardState(AuthState):
budgets: dict[int, dict[int, float]] = {}
available_properties: list[Property] = []
selected_metrics: list[int] = []Option 2 is the better one if you can do it: every other With either fix, the row compiles to the lookup you'd expect: budgets?.[prop?.["id"]]?.[metric_id]This happens on the frontend, so I reproduced the exact |
Uh oh!
There was an error while loading. Please reload this page.
I am trying to render the
target_table_rowdynamically for eachproperty_target_table, which in turn, renders for each value in theavailable_propertiesvariable (see towards the end for definition of this part)The problem is in rendering the python variable called
budget_value(not a Reflex Var)The statement which sets it's value:
TargetWizardState.budgets[property_id][metric_id]returns an error:
For context, below is how
TargetWizardState.budgetsis defined:I am setting the value for this State variable already using a DB call.
My goal is simple:
For each of the rendered
target_table_row, show thebudget_valuethat corresponds to theproperty_idandmetric_idcoming into thetarget_table_rowfunctionThe problematic code:
Any help is much appreciated!
Thanks.
All reactions