Ember.js:未捕获的类型错误:无法读取 transitionTo 上未定义的属性 'enter'

标签 ember.js ember-data ember-router

我有一个相当简单的 Ember.js 应用程序。在一个 View 中,我调用 this.transitionTo 这给了我错误:

未捕获的类型错误:无法读取未定义的属性“输入”

错误位于 ember.js 的第 24596 行,其中 currentState 未定义

以下是我的应用程序的相关部分:

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>

这个回应是:
{
   "calculations":[
      {
         "id":10,
         "target_goal":3107800.0,
         "target_return":0.089,
         "expected_return":0.0708,
         "downside_probability":0.0489
      }
   ]
}

该应用程序按预期工作,直到我专注于文本字段之外,然后出现错误。

Ember :1.5.1

Ember 数据:1.0.0-beta.8.2a68c63a

Handlebars :1.2.1

jQuery:1.11.1

最佳答案

过去的kingpin2k是完全错误的,我从观点上错过了关于过渡的陈述。我道歉。
transitionTo不支持来自组件的(至少从我能找到的任何文档中)

您需要从组件中发送一个 Action 并在您的 Controller 或路由中捕获它。

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

关于Ember.js:未捕获的类型错误:无法读取 transitionTo 上未定义的属性 'enter',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24421147/

相关文章:

javascript - 使用 HTMLBars 绑定(bind)静态和动态类

javascript - 使用通过 Ember 中的文本字段添加的项目更新页面

ember.js - Ember 未发布日期属性

ember-data - ember-data 中的 find、findAll 和 findQuery 有什么区别

javascript - 使用 Ember.js 加载属于父模型的数据

javascript - 在 Ember.js pre-4 中填充直接 url 访问的内容

templates - 如何使用 Ember.Handlebars.compile() 在类定义中声明 Ember 模板?

javascript - EmberJS 需要操作键

ember.js - 在最新的 Ember 中,如何仅使用模型的 id/name 链接到路由,而不是在链接页面中提供其所有属性?

ember.js - Ember - 为每个路由设置动态页面标题