Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hyperscipt doesn't work inside of map/loop #450

Open
8483 opened this issue Dec 16, 2018 · 0 comments
Open

Hyperscipt doesn't work inside of map/loop #450

8483 opened this issue Dec 16, 2018 · 0 comments

Comments

@8483
Copy link

8483 commented Dec 16, 2018

I am trying to create virtual table rows with a loop, but they don't appear.

The rendering works, but only to the tbody. This is the resulting HTML.

<div>
    <table>
        <tbody></tbody>
    </table>
</div>

The code

var h = require('virtual-dom/h');
var createElement = require('virtual-dom/create-element');

function view(state) {

    function renderRows() {
        var rows = []
        for (var i = 0; i < state.items.length; i++) {
            var item = state.items[i]
            rows.push(
                h('tr', [
                    h('td', item.documentDate),
                    h('td', item.documentKey)
                ])
            )
        }
        return rows
    }

    let tableRows = renderRows()

    return h('div', [
        h('table', [
            h('tbody', tableRows)
        ])
    ]);
}

var tree = view(state);
var rootNode = createElement(tree);
document.getElementById("app").appendChild(rootNode);

How can I get this to work?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant