我有一个简单的应用程序,它必须正确显示 JSON 对象数据列表。在我导航到索引页面并单击链接“风险类型”后,我提出了以下一组错误(来自 Chrome Ember 检查器):
DEPRECATION: Action handlers contained in an events object are deprecated in favor of putting them in an actions object (error on )
Error while loading route
Uncaught #Object
我怀疑错误源于我的商店定义。当我将修改路线的模型定义为
var mod = rt;
代替
var mod = this.store.findAll('risktype');
一切正常。
响应(2 个 JSon 对象的数组)来自 Tomcat 服务器上的 Java servlet。跟踪(附加)显示 responseText 是从后端服务器返回的正确获取的。
有人知道吗?
这是我的代码:
var App = Ember.Application.create({
LOG_TRANSITIONS: true,
LOG_TRANSITIONS_INTERNAL: true,
});
App.Router.map(function () {
this.route('risktypes', {path: '/risktypes'});
});
App.RisktypesRoute = Ember.Route.extend({
model: function() {
var mod = this.store.findAll('risktype');
// var mod = rt;
return mod;
}
});
var rt = [ { 'id': 1011, 'code': 'CODE1', 'description': 'Type 1', 'state': 'NEW' },
{ 'id': 2021, 'code': 'CODE2', 'description': 'Type 2', 'state': 'VALID' }]
App.RisktypesController = Ember.ArrayController.extend();
App.Store = DS.Store.extend({
adapter: DS.RESTAdapter.extend({
namespace: 'ember-profiler-webapp/app'
})
// , revision: 1
});
App.store = App.Store.create();
App.Risktype = DS.Model.extend({
code: DS.attr('string'),
description: DS.attr('string'),
state: DS.attr('string')
})
Here is file index.html:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
<script src="js/scripts/jquery-1.10.2.js" type="text/javascript" charset="utf-8"></script>
<script src="js/scripts/handlebars-1.0.0.js" type="text/javascript" charset="utf-8"></script>
<script src="js/scripts/ember-1.0.0.js" type="text/javascript" charset="utf-8"></script>
<script src="js/scripts/ember-data-beta-3.js" type="text/javascript" charset="utf-8"></script>
<script src="js/app/app1.js" type="text/javascript" charset="utf-8"></script>
<script type="text/x-handlebars" id="application">
<div id="mainArea">
<h1>(application)</h1>
{{outlet}}
</div>
</script>
<script type="text/x-handlebars" id="index">
<h1>(index)</h1>
<h2>This is the index template.</h2>
{{#link-to 'risktypes'}}
Risk types
{{/link-to}}
</script>
<script type="text/x-handlebars" id="risktypes">
<h2>This is the risktypes template.</h2>
<table>
<tr><th>Code</th><th>Description</th><th>State</th></tr>
{{#each controller}}
<tr>
<td>{{code}}</td>
<td>{{description}}</td>
<td>{{state}}</td>
{{/each}}
</table>
</script>
</head>
<body bgcolor="#ffffff">
</body>
</html>
下面的错误消息修改到跟踪“加载路由时出错”以下没有改进:
Object {readyState: 4, getResponseHeader: function, getAllResponseHeaders: function, setRequestHeader: function, overrideMimeType: function…}
abort: function ( statusText ) {
always: function () {
complete: function () {
done: function () {
error: function () {
fail: function () {
getAllResponseHeaders: function () {
getResponseHeader: function ( key ) {
overrideMimeType'risktypes': function ( type ) {
pipe: function ( /* fnDone, fnFail, fnProgress */ ) {
progress: function () {[
promise: function ( obj ) {
readyState: 4
responseText: "[ { 'id': 1011, 'code': 'CODE1', 'description': 'Type 1', 'state': 'NEW' },
{ 'id': 2021, code''code': 'CODE2', 'description': 'Type 2', 'state': 'VALID' }]"
setRequestHeader: function ( name, value ) {
state: function () {
status: 200
statusCode: function ( map ) {
statusText: "OK"
success: function () {
then: null]
__proto__: Object}
看起来我没有正确使用 Ember Data。
我修改了后端服务器返回的 JSON 对象。曾是:
[
{ 'id': 11, 'code': 'CODE1', 'description': 'Type 1', 'state': 'NEW' },
{ 'id': 21, 'code': 'CODE2', 'description': 'Type 2', 'state': 'VALID' }
]
修改为以下内容没有改变:
{ 'risktypes':
[
{ 'id': 11, 'code': 'CODE1', 'description': 'Type 1', 'state': 'NEW' },
{ 'id': 21, 'code': 'CODE2', 'description': 'Type 2', 'state': 'VALID' }
]
}
有人对此有提示吗?对于这样一个微不足道的初学者错误,切换到 Angular.js 将是一种耻辱!
谢谢