lundi 8 juin 2015

Creating new array item from input values using Ember.Copy

I've just recently started learning something about Ember from the latest Tuts+ tutorial 'EmberJS Framework Basics' (published May 6, 2015). The tutorial uses the 'Ember Starter Kit' as a base and gradually adds more functionality.

I'm having a problem with an action "create" within a controller that handles submitted input values to be added to an array. Specifically, the line 'var newProject = Ember.copy(this.content);' seems to be causing the issue.

This is the action code:

`create: function(){

    var newProject = Ember.copy(this.content);
    this.get('controllers.projects').addObject(newProject);
    this.transitionToRoute('projects');

}`

The full code so far is here: http://ift.tt/1JDIgl5 Click on 'Go to projects' -> 'Add new project' -> 'Create' to see the effect.

Apart from 'why doesn't it work?!' my questions are:

  • Is Ember.Copy(this.content) deprecated?
  • What exactly is 'this.content'?

Note that if I use

var newProject = {id: App.projects.length+1, title: this.title, about: this.about};

the action does it's job fine.

Please note also that my code is not a copy of what is shown in the tutorial, but it is essentially the same (I think!)

Hope you can help and thanks in advance.

Aucun commentaire:

Enregistrer un commentaire