Join Kai Gittens for an in-depth discussion in this video Define a model with DS.Model(), part of Up and Running with Ember.js.
In this video, we'll continue creating the notes page by defining our models. And the ds.model class will help us with this. So, I'll go to snippet.txt and highlight and copy the code on lines 40 through 46. Then, go back to @.js and I'm going to scroll all the way to the bottom and paste in the code we just copied directly at the bottom. I'll just add one line of white space, just so we can see things a little better.
And I'll remove the space before the a in at.note. We don't need it. So, on line 88 we're creating a name space model called note and on line 89, we're defining its only attribute called copy. And, as mentioned in the last video, ds.model describes data, but doesn't store it. We've included data inside model hooks and jason files in previous chapters, but were not doing that now. Our data will consist of notes we add.
And the notes can be either edited or deleted inside a browser. In that scenario, we can't just add a dataset to a file like we've done before. But in order to add, edit, and delete these notes, our code does need to know what model to perform these tasks against. And also needs to know what it's attributes are. DS stored tells our code what the model is. And in this case, the model only has that copy attribute, and it's being defined as an attribute with the DS.outer method. That method tells our entire application, hey, this model is called note, and it has an attribute called copy. The copy attribute will be the actual text of any notes we create. So, in other words, if we were to create 100 notes in our app, that group of 100 will represent the entire model set and they would live in the store that we discussed. Each single entry will represent a unit of model data in our group. Each unit has an attribute called copy, and that attribute will be made up of our actual note copy. It's best to think of this attribute as a model property we've discussed in previous chapters. The property title of artist exhibits, for example. The copy attribute will constantly be watched and observed in our app. When we start writing code that let's us change our notes, you'll see that it needs to look at the copy attribute quite a bit. Now that the model's been defined for the notes page, let's start giving this page some functionality
- Installing Ember Inspector
- Reviewing routes with Ember Inspector
- Loading templates with routes
- Creating links with the link-to helper
- Adding component templates
- Loading model data
- Customizing components
- Building nested routes and route objects
- Loading data with object and array controllers
- Creating interfaces