gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 19:06:00 24 4
gpt4 key购买 nike

我有一个相当简单的 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com