- EmberJS Tutorial
- EmberJS - Home
- EmberJS - Overview
- EmberJS - Installation
- EmberJS - Core Concepts
- Creating and Running Application
- EmberJS - Object Model
- EmberJS - Router
- EmberJS - Templates
- EmberJS - Components
- EmberJS - Models
- EmberJS - Managing Dependencies
- EmberJS - Application Concerns
- EmberJS - Configuring Ember.js
- EmberJS - Ember Inspector
- EmberJS Useful Resources
- EmberJS - Quick Guide
- EmberJS - Useful Resources
- EmberJS - Discussion
EmberJS - Defining Models
Model is a class that extends the functionality of the Ember Data which specifies relationships with other objects. In Emberjs, every route has an associated model and when a user refreshes the page, the contents of page should be represented by a model.
The model can be created by using the following command −
ember generate model model_name
It creates the file structure under app/models/model_name.js as shown below −
import DS from 'ember-data'; export default DS.Model.extend ({ });
Defining Attributes
The DS.attr is used to specify attributes for a model. This also takes an optional second parameter as hash.
For instance −
import DS from 'ember-data'; export default DS.Model.extend ({ bookName: DS.attr(), authorName: DS.attr() });
For more about defining models and attributes along with an example, see the following section.
emberjs_model.htm
Advertisements
To Continue Learning Please Login
Login with Google