未捕获的TypeError:没有方法'storeKeyFor'

时间:2013-09-05 13:54:10

标签: javascript sproutcore

我是Sproutcore的新手,正在学习基础知识。我遇到了以下问题:

我有一个模特:

Myapp.Space = SC.Record.extend({
    id: SC.Record.attr(Number),
    name: SC.Record.attr(String),
    creator: SC.Record.toOne('Myapp.User', {isMaster: YES, inverse: 'space'})
});

Myapp.User = SC.Record.extend({
    id: SC.Record.attr(String),
    name: SC.Record.attr(String)
});

还有一个控制器:

Myapp.spaces_controller = SC.ArrayController.create(
 {
       allowsMultipleSelection: NO,
        selection: null,
        isEditable: YES
});

在我的数据源中,我正在进行远程GET调用:

fetch: function(store, query) {
            var recordType = query.get('recordType');
            var url;
            if (recordType === Myapp.Space) {
                url = "spaces"
            }
            SC.Request.getUrl(this.baseApiUrl(store) + url).set('isJSON', YES)
                .notify(this, this._didFetch, {
                    store: store,
                    recordType: recordType
                }).send();
        },

_didFetch: function (response, params)  {
            var store = params.store,
                recordType = params.recordType;
            if (SC.$ok(response)) {
                store.loadRecords(recordType, response.get('body'));
            }
        },

当我打电话

Myapp.spaces_controller.set('content', Myapp.store.find(Myapp.Space));

(用户登录后)我收到错误:

Uncaught TypeError: Object function (props) {
      this.__sc_super__ = ret.prototype;
      return this._object_init(props);
    } has no method 'storeKeyFor' javascript.js?1377681200:11281
SC.Store.SC.Object.extend.loadRecord javascript.js?1377681200:11281
SC.Store.SC.Object.extend.loadRecords javascript.js?1377681200:11337
Myapp.DataSource.SC.DataSource.extend._didFetch data_source.js?1378388369:39
SC.Response.SC.Object.extend._notifyListeners javascript.js?1377681198:392
SC.Response.SC.Object.extend.notify javascript.js?1377681198:413
(anonymous function) javascript.js?1377681198:314
SC.run javascript.js?1377681203:14741
SC.Response.SC.Object.extend.receive javascript.js?1377681198:298
SC.XHRResponse.SC.Response.extend.finishRequest javascript.js?1377681198:628
SC.mixin.handle javascript.js?1377681199:4249
(anonymous function)

我可以访问响应正文中的对象,但商店没有获取数据。

我在网上找不到任何错误。有人可以帮忙吗?

1 个答案:

答案 0 :(得分:0)

Object function(props) ... has no method 'storeKeyFor'的错误在我看来就像你试图在类上调用函数而不是在该类的实际实例上调用。

我的第一个猜测是你的recordType被设置为实际的类而不是字符串,这可能会导致一些问题。一般来说,我建议在处理记录类型时使用'MyApp.Space',因为它将在运行时进行评估和查找。如果由于某种原因无法找到它,它会抛出一个更好的消息。

希望这有帮助!