this.ti...">

Riot.js 2: False Value Attribute

I need to have an attribute that can have a value of 0 ( 0 )

Riot Template:

 <my-tag time="{ time }"> this.time = condition ? '10' : '0' </my-tag> 

Desired Result:

 <my-tag time="0"></my-tag> 

However, Riot automatically omits the entire attribute if it has a false value:

 <my-tag></my-tag> 

My current workaround:

 this.on('updated', () => { $(this.root).attr('time', this.time) }) 

In other words, I need the time attribute in order to have the exact value of the time property.

Edit:

It looks like this has changed from 2.2.4.

Demo with Riot 2.2.4

this works as expected - both tags display the time attribute with the corresponding value

Demo with Riot 2.3.13

this failure: a tag with an attribute set to false deleted the entire attribute

+5
source share
2 answers

This works in clutter v2.3.18:

 <my-tag time="{ time ? '10' : '0'}"> <script> this.time = false; </script> </my-tag> 

will generate

 <my-tag time="0"></my-tag> 
+1
source

Try prefixing your attribute with "riot -"

 <my-tag riot-time="{ time }"> 

I had a similar problem

 <div class="fldr" data-stat="{ s }"> 

When s = 0, displayed as

 <div class="fldr"> 

This worked in my case.

 <div class="fldr" riot-data-stat="{ s }"> 

Note that I am not using the Riot compiler, I am writing Javascript that the compiler will create, you may have to bypass the Riot compiler for this. Just look at your compiled my-tag.js and go from there.

Riot API docs at riot.tag () http://riotjs.com/api/#manual-construction

0
source

Source: https://habr.com/ru/post/1240505/


All Articles