Search code examples
jaydatadynamic-tables

How to retrieve field names in jaydata


I have a simple database in Jaydata:

$data.Entity.extend("Person", {
Name: { type: String, required: true},
LastName: {type: String, required: true},
DepartmentId: {type: int}
});

$data.EntityContext.extend("PersonDatabase", {
People : { type : $data.EntitySet, elementType : Person}
});

var Database1= new PersonDatabase("MyDatabase");

But suppose I don't know the fields of the database I have. Assume I only know the variable Database1 so I need to make a loop which returns column names(fields of "Person"). How can I make that so I can make a dynamic table which can show whatever simple database(#x columns, #y rows) data I will have?


Solution

  • If you have a type in hand for example the Person class, call type.getFieldNames() for and array of public mapped field names (technical fields are not visible). To access each and every field with full metadata consult type.memberDefinitions or type.memberDefinitions.toArray()

    The http://admin.jaystack.net site is build with fully generic table routines powered by knockout: check out admin.jaystack.net for an example (you need to register for a free account to access the admin site)