Setting a bool published attribute with @published

柔情痞子 提交于 2019-12-08 15:58:29
montyr75

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;

Then you can use it in the HTML like this:

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

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).

Hope that helps!

In response to @montyr75 s answer.

PublishedProperty(reflect: true) is necessary when you want the value of the field available in the DOM for example to be used in CSS selectors. If it is only used in code @published is fine. (still not entirely sure about this though).

If you want a boolean attribute that indicates true by the presence of the attribute and false by the a absence use a question mark like <description-form isVisible?="{{reference}}">

I tried a boolean attribute like you use it in your code and it just worked for me.

Another hint: If you want changes in your collections to take effect in the view you should make the collections observable @observable Map<String, dynamic> datamap = toObservable({});

To simply answer your question:

The string from label will be correctly resolved. If you have a boolean published attribute isVisible just use <description-form></description-form> if you want isVisible to be false and <description-form isVisible></description-form> if you want it to be true.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!