This article does not currently provide any useful information. Either we need to add useful info or delete it. Hidden for now.
Use LoopBack Definition Language (LDL) to define LoopBack data models in JSON or JavaScript.
Use slc loopback:model
command to crete a JSON definition of a model. For more information, see Model generator.
The simplest form of a property definition in JSON has a propertyName: type
element for each property. The key is the name of the property and the value is the type of the property. For example:
{ "id": "number", "firstName": "string", "lastName": "string" }
This example defines a user
model with three properties:
- id - The user id, a number.
- firstName - The first name, a string.
- lastName - The last name, a string.
Each key in the JSON object defines a property in the model that is cast to its associated type. See LoopBack types for more information.
You can also describe the same model in JavaScript code:
var UserDefinition = { id: Number, firstName: String, lastName: String }
The JavaScript version is less verbose, since it doesn't require quotes for property names. The types are described using JavaScript constructors, for example, Number
for "Number"
. String literals are also supported.
To use the model in code is easy, because LoopBack builds a JavaScript constructor (or class) for you.
Attachments:



