0

我有一个休息适配器:

App.Adapter = DS.RESTAdapter.extend({
    bulkCommit: true,
    url: 'http://10.0.0.106/bank',
    ajax: function (url, type, hash) {
        hash.url = url;
        hash.type = type;
        hash.context = this;
        hash.headers = {
            'Session-Token': '65f1b8925f8eb2780730a4a2993693699e9a98dad5d2995452c24758d2c59706'
        };

        if (hash.data && type !== 'GET') {
            hash.data = JSON.stringify(hash.data);
        }

        $.ajax(hash);
    }
});

App.Store = DS.Store.extend({
    revision: 13,
    adapter: App.Adapter
});

一条路线:

App.UsersRoute = Ember.Route.extend({
    model: function() {
        return App.User.find();
    }
});

一个模型 :

App.User = DS.Model.extend({
    firstname: DS.attr("string"),
    lastname: DS.attr("string"),
    email: DS.attr("string"),
    user_id: DS.attr("string"),
    role: DS.attr("string"),
    phone: DS.attr("string")
});

该请求效果很好,并给了我:

{
    "error": null,
    "payload": {
        "bank_users": [{
                "firstname": "Ugo",
                "lastname": "Doe",
                "email": "ugo@doe.com",
                "user_id": 1,
                "role": "BANK_USER",
                "phone": null
            }, {
                "firstname": "Ugo Clone",
                "lastname": "Doe",
                "email": "ugo-clone@doe.com",
                "user_id": 2,
                "role": "BANK_USER",
                "phone": null
            }
        ]
    }
}

在我的模板中;我就是这样:

<h2>this is users !!</h2>

{{#each model}}
    {{firstname}}
{{/each}}

错误是:Uncaught TypeError: Cannot call method 'then' of undefined

这发生在 ember-data 中,这里:

  findAll: function(store, type, since) {
  var root, adapter;

  root = this.rootForType(type);
  adapter = this;

  return this.ajax(this.buildURL(root), "GET",{
    data: this.sinceQuery(since)
  }).then(function(json) {
    adapter.didFindAll(store, type, json);
  }).then(null, rejectionHandler);
}

我似乎since是未定义的;我做错了什么?:)

4

1 回答 1

1

我猜,因为您RESTAdapter ajax应该在最后一行覆盖该方法

$.ajax(hash);

不是宁可吗?

return $.ajax(hash);

希望能帮助到你。

于 2013-06-19T19:26:39.987 回答