From 515dc7819c0d7f7c52715bd7da114032f1f5022b Mon Sep 17 00:00:00 2001 From: Todd Jordan Date: Sat, 20 Feb 2016 16:51:21 -0500 Subject: [PATCH] Add documentation regarding ember objects as data. --- tests/dummy/app/routes/demos/data.js | 10 +++++++-- tests/dummy/app/templates/demos/data.hbs | 26 ++++++++++++++++++------ 2 files changed, 28 insertions(+), 8 deletions(-) diff --git a/tests/dummy/app/routes/demos/data.js b/tests/dummy/app/routes/demos/data.js index 0a916b4..4739713 100644 --- a/tests/dummy/app/routes/demos/data.js +++ b/tests/dummy/app/routes/demos/data.js @@ -1,10 +1,16 @@ import Ember from 'ember'; +const Feedback = Ember.Object.extend({ + name: Ember.computed('firstName', 'lastName', function () { + return `${this.get('firstName')} ${this.get('lastName')}`; + }) +}); export default Ember.Route.extend({ model() { const basicModel = this.modelFor('demos'); - const data = Ember.Object.create({ - name: 'Todd Jordan', + const data = Feedback.create({ + firstName: 'Todd', + lastName: 'Jordan', feedback: 'Ember + Alpaca = Awesome', ranking: 'excellent' }); diff --git a/tests/dummy/app/templates/demos/data.hbs b/tests/dummy/app/templates/demos/data.hbs index 5c4a446..62bf505 100644 --- a/tests/dummy/app/templates/demos/data.hbs +++ b/tests/dummy/app/templates/demos/data.hbs @@ -1,15 +1,24 @@

Data

-

This form has data pre-filled in its fields, provided apart from its schema.

+

This form has data pre-filled in its fields, provided apart from its schema. +The component will take both ember objects and plain JavaScript objects as arguments.

{{dynamic-form schema=model.basicModel data=model.data}}
-

The dynamic-form component also takes a data parameter to populate fields. The component will attept to populate any field that has a matching key in the data object.

-

Below we will take our basic schema and add a data object to populate fields.

+

The dynamic-form component also takes a data parameter to populate fields. +It will populate any field that has a matching key in the data object.

+

In the form example above we pass in an ember object called Feedback with a computed property as our data argument.

{{#highlight-js}}
/app/routes/demos/data.jsimport Ember from 'ember';
+
+const Feedback = Ember.Object.extend({
+  name: Ember.computed('firstName', 'lastName', function () {
+    return `${this.get('firstName')} ${this.get('lastName')}`;
+  })
+});
+
 const basicSchema = {
   "schema": {
     "title":"User Feedback",
@@ -56,12 +65,15 @@ const basicSchema = {
 };
 
 export default Ember.Route.extend({
+
   model() {
-    const data = Ember.Object.create({
-      name: 'Todd Jordan',
+    const data = Feedback.create({
+      firstName: 'Todd',
+      lastName: 'Jordan',
       feedback: 'Ember + Alpaca = Awesome',
       ranking: 'excellent'
     });
+
     return {
       basicSchema,
       data
@@ -70,5 +82,7 @@ export default Ember.Route.extend({
 });
{{/highlight-js}} -{{#highlight-js}}
/app/templates/demos/data.hbs\{{dynamic-form schema=model.basicSchema data=model.data}}
{{/highlight-js}} +{{#highlight-js}}
/app/templates/demos/data.hbs
+\{{dynamic-form schema=model.basicSchema data=model.data}}
+
{{/highlight-js}}