jvangore31
jvangore31

Reputation: 31

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);
        }

      }

});

Upvotes: 0

Views: 301

Answers (1)

user6586783
user6586783

Reputation:

Object keys taskData and personData are not variables, but keys of an object which is then passed as an argument to the extend function. 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);
        }

      }

});

Upvotes: 1

Related Questions