gpt4 book ai didi

dart - 使用@published设置 bool 发布属性

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

我有以下.dart组件

@CustomTag('description-form')
class DescriptionForm extends PolymerElement {
@observable Map<String, dynamic> datamap = {};
@observable String description = '';

@published
String get label => readValue(#label);
set label(String value) => writeValue(#label, value);

@published
bool get isVisible => readValue(#isVisible);
set isVisible(bool value) => writeValue(#isVisible, value);

DescriptionForm.created() : super.created();

void publish() {
datamap['description'] = description;
}

@override
void attached() {
super.attached();
datamap['receiver'] = dataset['receiver'];
}
}

要使用发布的属性,我将以一种形式进行以下操作

  <description-form
label = 'Others'
isVisible = false
data-receiver = 'shared| description-form --> dynamic-chkbx'>
</description-form>

标签解析后,isVisible不会解析。
设置使用 @published发布的 bool(boolean) 值的正确机制是什么?

最佳答案

通常, bool(boolean) 属性基于它们是否存在而工作。因此,如果您像这样在类中设置属性:

@PublishedProperty(reflect: true) bool isVisible = true;

然后,您可以像下面这样在HTML中使用它:

  <description-form
label = 'Others'
isVisible
data-receiver = 'shared| description-form --> dynamic-chkbx'>
</description-form>

如果标签上存在 isVisible,则它是类中的 true,将类的属性更改为 false会删除标签上的属性(这要归功于 reflect: true)。

希望有帮助!

关于dart - 使用@published设置 bool 发布属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26769677/

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