我有一个相当简单的Ember.js应用程序。在 View 内部,我称之为this.transitionTo,这给了我错误:
未捕获的TypeError:无法读取未定义的属性“输入”
错误发生在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完全错误,我从 View 中错过了有关过渡的声明。我道歉。
不支持来自组件的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