profile
viewpoint

Ask questionsfor with if example gives js error

I'm trying to do a template with a "for" that has an "if" within it and can't get it to work, gets an error. I found the example on the readme page is very similar and gets the same error.

Example conditional branch from README.md that gives error:

<main>
  <title>{{ data.title }}</title>
  <tweets for="data.tweets">
    <section if="data.content">{{ data.content }}</section>
  </tweets>
</main>

Full code to run:

<script src="mikado.debug.js"></script>
<div id="app"></div>
<template id="tpl">
<main>
  <title>{{ data.title }}</title>
  <tweets for="data.tweets">
    <section if="data.content">{{ data.content }}</section>
  </tweets>
</main>
</template>

<script>
var data = {
    title: "Some title",
    tweets: [
        {content: "Text1"},
        {content: "Text2"},
        {content: "Text3"},
    ]
}
var view = new Mikado(Mikado.compile('tpl'));
view.mount(document.getElementById('app'));
view.render(data);
</script>

Error is: VM14:3 Uncaught TypeError: Cannot set property 'hidden' of undefined

Code generated:

(function anonymous(p, s, data, index, view) {
    "use strict";
    var self, v;
    if (true) {
        self.hidden = false;                 <----- self was never set, so gets error here
        self = p[1];
        v = data.content;
        if (self._text !== v) {
            self._text = v;
            self.nodeValue = v
        }
        ;self = p[0]
    } else
        self.hidden = true
}
)

Mikado 0.7.57

nextapps-de/mikado

Answer questions sqwishy

Is there a workaround for this?

Edit: For now I have replaced if="test" with if="(self=p[0]) && test" or whatever the "correct" p index is, but I have no idea if this is at all doing the right thing. But I'm curious if this is supposed to do much other than set the "hidden" attribute on the nodes?

useful!

Related questions

No questions were found.
source:https://uonfu.com/
Github User Rank List