在解决模型时中止了过渡

时间:2013-10-17 15:50:27

标签: model store ember-data routes

我有一个简单的应用程序,它必须正确显示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以获得如此微不足道的初学者错误会很遗憾!

由于

0 个答案:

没有答案