O'Reilly logo

Seven Mobile Apps in Seven Weeks by Tony Hillerson

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Day 2: Exchanging Notes

Or, Creating Notes and Calling the API

Today we’ll write the code to accept user input and create a note from the new note screen. Then we’ll get the notes displayed in a list on the main screen. We’ll also get the notes saving to and loading from the API.

Creating a New Note

Let’s get started by creating a new note. First, to store note data locally we’ll create a data model.

Creating a Note Data Model

Add this class to a new file called data/NotesDataModel.js:

 'use strict'​;
 
 class​ NotesDataModel {
 
  notes:Array<Object> = [];
 
  createNewNote(title​:​String, body​:​String) {
 this​.notes.push({title: title, body: body});
  }
 }

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required