Question

I'm trying to write an ejs Template, which shows all key's and values from an javascript MVC Model. According to this this answer, I've tried the following:

Person.findOne({id: 51}, function(person) {
     $("#editcustomerform").html('./html/person_2.ejs', person);
});

The ejs looks like this:

<form id="personForm">
     <table class="ui-widget-content table">
        <thead ><tr>
                <th style=" width: 100px">Feld</th>
                <th>Inhalt</th>
            </tr></thead>

        <tbody>
            <% $.each(this, function(key, value){  %>
            <tr>
                <td><%= key %>:</td>
                <td><input name="<%= key %>" id="<%= key %>" type="text" size="30" maxlength="30" value="<%= value %>"></td>
            </tr>
            <% }) %>
        </tbody>
    </table>

The loaded Data looks like the following:

{"id":51,"name":"Max","age":20}

Everything is working. The problem is, that all attributes like constructor, Class, update, etc. are shown in the form. I didn't found a function from JavascriptMVC, which gives me only the loaded Json data.

Do I need to parse the attributes id, name and age manually or is there a better way?

Was it helpful?

Solution

Use .hasOwnProperty() to tell whether a property belongs to the object itself or was inherited from Object.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top