How to send an object to .marko template and render its properties dynamically, in a table

415 Views Asked by At

Im doing some homework here. Build a server that handles a requisition to list all registers from a database, dynamically. Im using node js and the modules: express, marko and sqlite3. The db is set and has some registers for testing; (id, name, desc, price). The route '/planos' is set to return a promise, its .then function sends a .marko file, as first parameter, and an object, that is the result from a DAO to list all my stuff from the database, as second parameter. The DAO is working and the object with all the db registers is returning, but i cant get marko to print it in my html...

Im trying to get it right, but i dont know how to refer to the data in the object i passed to the template. A lot of "cant read 'property' of undefined" in the process...

//The route.

app.get('/planos', function(req, resp){
        planoDao = new PlanoDAO(db)
        planoDao.listagem().then(function(resultado){
            console.log(resultado)
            resp.marko(require('../views/plano/plano2.marko'), {
            planos: resultado
        })
        })

    })

//The .marko file

<table >
                        <tr>
                            <th>ID</th>
                            <th>Nomes</th>
                            <th>Descrição</th>
                            <th>Preços</th>
                        </tr>
                        <${out.global.planos? planos-tr : 'tr' }>
                            <td>${input.planos.id}</td>
                             <td>${out.global.nome}</td>
                              <td>${out.global.desc}</td>
                               <td>${out.global.price}</td>
                        </>
                        <if(data.planos)>

                                <for |{planos}| in=data.planos>
                                    <tr>
                                        <td>ID: ${data.id}</td>
                                        <td>${data.planos.nome}</td>
                                        <td>${data.planos.desc}</td>
                                        <td>${data.planos.price}</td>
                                    </tr>
                                </for>
                        </if>

            </table>
1

There are 1 best solutions below

0
On BEST ANSWER
                        <if(data.planos)>
                                <for(plano in data.planos)>
                                    <tr>
                                        <td>${plano.id}</td>
                                        <td>${plano.name}</td>
                                        <td>${plano.desc}</td>
                                        <td>${plano.price}</td>
                                    </tr>
                                </for>
                        </if>