jvangore31 jvangore31 - 4 months ago 8
Javascript Question

Array variable in an ember controller

-I'm kind of new to ember js and javascript in general and I can't seem to figure out why my methods keep spitting out the error that both

taskData
and
personData
are undefined. Any feedback is appreciated!

import Ember from 'ember';

export default Ember.Controller.extend({

taskData: [],
personData: [],



actions: {

taskData: [],
personData: [],

saveTask() {

var task = this.get("task");
taskData.push(task);
},

savePerson()
{
var person = this.get("person");
personData.push(person);
},

print(){

alert(taskData);
alert(personData);
}

}

});

Answer

Object keys taskData and personData are not variables, but keys of object whcih is passed as arguemnts to extend command. You need to use this keyword.

import Ember from 'ember';

export default Ember.Controller.extend({

    taskData: [],
    personData: [],



      actions: {

          taskData: [],
          personData: [],

        saveTask() {

            var task = this.get("task");
            this.taskData.push(task);
        },

        savePerson()
        {
            var person = this.get("person");
            this.personData.push(person);
        },

        print(){

            alert(this.taskData);
            alert(this.personData);
        }

      }

});