Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ember.js: Uncaught TypeError: Cannot read property 'enter' of undefined on transitionTo

I have a fairly simple Ember.js app. Inside a view I call this.transitionTo which gives me the error:

Uncaught TypeError: Cannot read property 'enter' of undefined

The error is in ember.js at line 24596, where currentState is undefined

Here are the relevant parts of my app:

window.Plan = Ember.Application.create({});

        Plan.Router = Ember.Router.extend({
        location: 'hash'
    });

    Plan.IndexController = Ember.ObjectController.extend({

    });


    Plan.Router.map(function() {
        this.route('application', { path: '/' })
        this.route('index', { path: "/:current_savings/:monthly_deposit/:time_horizon" });
    });

    Plan.ApplicationRoute = Ember.Route.extend({
        redirect: function(){
            this.transitionTo('index', 200, 200, 200);
        }
    })

    Plan.IndexRoute = Ember.Route.extend({
        model: function(params) {
            var result = this.store.find('calculation', params).then(function(data) {
                return data.content[0];
            });

            return result;
        }
    });

    Plan.CurrentSavingsTextField = Ember.TextField.extend({
        focusOut: function() {
            this.transitionTo('index', 150, 200, 200);
        }
    });

    Plan.MonthlyContributionTextField = Ember.TextField.extend({
        focusOut: function() {
            this.transitionTo('index', 150, 200, 200);
        }
    });

    Plan.TimeHorizonTextField = Ember.TextField.extend({
        focusOut: function() {
            this.transitionTo('index', 150, 200, 200);
        }
    });

Plan.Calculation = DS.Model.extend({
    target_goal: DS.attr('number'),
    target_return: DS.attr('number'),
    expected_return: DS.attr('number'),
    downside_probability: DS.attr('number')
});

Plan.ApplicationAdapter = DS.RESTAdapter.extend({
    namespace: 'plan/' + window.targetReturnId
});

HTML:

<script type="text/x-handlebars" data-template-name="index">

    <div>
        <div>Starting Balance: {{view Plan.CurrentSavingsTextField size="10"}}</div>
        <div>Monthly Contribution: {{view Plan.MonthlyContributionTextField size="10"}}</div>
        <div>Time Horizon: {{view Plan.TimeHorizonTextField size="10"}}</div>
    </div>
    <div>
        <span>Plan Goal: {{target_goal}}</span>
        <span>Required Return: {{target_return}}</span>
        <span>Exp Return:  {{expected_return}}</span>
        <span>Downside Probability: {{downside_probability}}</span>
        <span>Time Horizon: {{time_horizon}}</span>
    </div>

</script>

This response is:

{
   "calculations":[
      {
         "id":10,
         "target_goal":3107800.0,
         "target_return":0.089,
         "expected_return":0.0708,
         "downside_probability":0.0489
      }
   ]
}

The app works as expected until I focus out of the text field, then I get the error.

Ember : 1.5.1

Ember Data : 1.0.0-beta.8.2a68c63a

Handlebars : 1.2.1

jQuery : 1.11.1

like image 996
Brad Urani Avatar asked Jun 26 '14 01:06

Brad Urani


1 Answers

Past kingpin2k was totally wrong, I missed the statement about the transition from the view. I apologize.

transitionTo from a component isn't supported (at least from any documentation I could find)

You'll want to send an action out of the component and capture it in your controller or route.

Plan.CurrentSavingsTextField = Ember.TextField.extend({
    focusOut: function() {
        this.sendAction('go', 199, 200, 201);
    }
});


Plan.IndexRoute = Ember.Route.extend({
    model: function(params) {
        var result = this.store.find('calculation', params);
      //if you just wanted the first object
     // result.then(function(collection){
     //   return collection.get('firstObject');
     // });
        return result;
    },
  actions:{
    go: function(a, b, c){
      console.log('transition');
      this.transitionTo('index',a,b,c);
    }
  }
});

http://emberjs.jsbin.com/OxIDiVU/749/edit

like image 53
Kingpin2k Avatar answered Nov 15 '22 12:11

Kingpin2k