gpt4 book ai didi

dart - 在模板dom重复中使用计算的属性似乎实际上并未获取数据

转载 作者:行者123 更新时间:2023-12-03 03:43:24 25 4
gpt4 key购买 nike

我一直在使用的用例是,我有一些标记如下。

<my-radiolist value="{{myValue}}">
<template is="dom-repeat" items="{{test}}">
<my-radiobutton value="{{item}}" label="{{item}}"></my-radiobutton>
</template>
</my-radiolist>

以及何时将测试定义为:
@property List<int> test = [1,2,3];

它工作正常。

现在,我想通过遍历更复杂的对象来填充此列表。我想对其进行计算,然后执行给定的功能。我将示例更新如下:
@Property(computed:"getTest()")
List<Map> test = null;

@reflectable
List<Map> getTest() {
print("Inside my getTest Function");
return [{"key": "test", "value": "test"}, {"key":"test 2","value":"test 2"}];
}

我注意到我的打印语句从未触发过,因此我的属性具有默认值,这意味着没有要迭代的内容。

我之前已经做过这些,但是对于模板中继器却没有。我做错什么了吗?

我的想法是,由于在更新参数时计算已更新,并且由于我未使用任何参数,因此在这种情况下使用计算属性不是我应该采取的措施。

最佳答案

The value is interpreted as a method name and argument list. The method is invoked to calculate the value whenever any of the argument values changes. Computed properties should never be written to directly. See Computed properties for more information.



如果没有参数,那么在我看来,这里的计算属性毫无意义。

另请参阅 https://github.com/dart-lang/polymer-dart/wiki/properties#computed-properties

关于dart - 在模板dom重复中使用计算的属性似乎实际上并未获取数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40088106/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com