Ember.js:未捕获类型错误:无法读取属性';输入';关于未定义的转换

Ember.js:未捕获类型错误:无法读取属性';输入';关于未定义的转换,ember.js,ember-data,ember-router,Ember.js,Ember Data,Ember Router,我有一个相当简单的Ember.js应用程序。在一个视图中,我称之为this.transitiono,它给出了一个错误: 未捕获的TypeError:无法读取未定义的属性“enter” 错误在第24596行的ember.js中,其中currentState未定义 以下是我的应用程序的相关部分: window.Plan = Ember.Application.create({}); Plan.Router = Ember.Router.extend({ locati

我有一个相当简单的Ember.js应用程序。在一个视图中,我称之为this.transitiono,它给出了一个错误:

未捕获的TypeError:无法读取未定义的属性“enter”

错误在第24596行的ember.js中,其中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:

该应用程序按预期工作,直到我的焦点离开文本字段,然后我得到错误

余烬:1.5.1

余烬数据:1.0.0-beta.8.2a68c63a

车把:1.2.1


jQuery:1.11.1

过去的kingpin2k是完全错误的,我错过了关于从视图过渡的声明。我道歉

不支持从组件转换到(至少从我能找到的任何文档中)

您将希望从组件中发送一个操作,并在控制器或路由中捕获它

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

这个问题已经很老了,但就我的谷歌搜索而言,它似乎仍然没有答案。在玩过(Ember 0.13.0)之后,我能够从组件内部获得以下代码:

this.get('_controller').transitionToRoute('index', 150, 200, 200);
controller的uufront确实感觉有点像黑客,用户代码不应该真正访问它
get('controller')
实际上返回的是完全不同的东西


我确实同意从视图(组件)导航不是最佳实践,但对于我的用例,我有一些组件可以放到仪表板中进行绘图等,这非常适合,而不是调用控制器操作。它帮助我将所有内容都隔离在一个组件中。

看起来这并不是所有相关的代码,因为这些代码可以正常工作。模型是什么样子的,服务器的响应是什么样子的?哪个适配器,序列化程序?它们看起来像什么?@kingpin2k我在你的jsbin中发现了未定义的错误。Chrome版本35.0.1916.153导致错误的是
CurrentSavingsTextField
focusOut
方法。您能解释一下{{{view Plan.CurrentSavingsTextField go='go'}}吗?这是将控制器操作的引用传递到视图中吗?我想这是有道理的,因为视图有它自己独立的控制器。它连接从组件传递的动作。这意味着当您调用
sendAction('go')
时,它将被转换为动作名称
go
,并传递给父控制器,然后向上移动路由树。如果您有多个组件,并且希望它们连接到组件之外的不同操作,或者如果您想忽略组件中的某个操作,您就不能连接到它。我已经几个月没有使用Ember了,所以我无法对此进行审查。如果有人想告诉我这是否正确,我会接受这个答案
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);
    }
  }
});
this.get('_controller').transitionToRoute('index', 150, 200, 200);