使用@published设置bool已发布的属性 [英] Setting a bool published attribute with @published
问题描述
我有以下.dart组件
I have the following .dart component
@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'];
}
}
要使用已发布的属性,我将执行以下操作
To use the published attributes, I would do the following in a form
<description-form
label = 'Others'
isVisible = false
data-receiver = 'shared| description-form --> dynamic-chkbx'>
</description-form>
当标签解析时,isVisible不会。
设置使用 @published
?
While label is resolved, isVisible does not.
What is the correct mechanism to set a bool that is published using @published
?
推荐答案
通常,布尔属性的工作原理是基于它们是否存在。因此,如果您在类中设置属性,像这样:
Typically, boolean attributes work based on whether they're present or not present. So if you set up the property in your class like so:
@PublishedProperty(reflect: true) bool isVisible = true;
然后,您可以在HTML中使用它:
Then you can use it in the HTML like this:
<description-form
label = 'Others'
isVisible
data-receiver = 'shared| description-form --> dynamic-chkbx'>
</description-form>
当标签上出现 isVisible
它在类中的 true
,并将类的属性更改为 false
删除标记上的属性
When isVisible
is present on the tag, it's true
in the class, and changing the class's property to false
removes the attribute on the tag (thanks to reflect: true
).
希望有所帮助!
这篇关于使用@published设置bool已发布的属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!