我在回复中得到了这个类型错误,我不知道store.find('someThread')期望的格式。 这是我的余烬:
App.RestAdapter = DS.RESTAdapter.extend({
url: 'http://mylocalhost:3000',
namespace: 'api',
serializer: DS.RESTSerializer.extend({
primaryKey: function(type) {
return '_id';
}
})
});
App.Store = DS.Store.extend({
revision: 12,
adapter: App.RestAdapter
});
App.VideoRoute = Ember.Route.extend({
model: function() {
console.log("video..", this.store.find('video'));
return true;
}
});
这是节点部分:
exports.list = function(req, res) {
Video.find(function(err, videos) {
var payload = { video: {name: "sampleName"}};
return res.send(200, JSON.stringify(payload));
});
}
以下是响应的console.log:
Class {constructor: function, reason: null, isPending: undefined, isSettled: undefined, isRejected: false…}
__ember1385638132476: undefined
__ember1385638132476_meta: Meta
_super: undefined
arrangedContent: (...)
content: (...)
isRejected: true
reason: TypeError
message: "Object function () {↵ if (!wasApplied) {↵ (...)"
stack: (...)
get stack: function () { [native code] }
set stack: function () { [native code] }
__proto__: Error
__proto__: Object
如果我只发送一个字符串,我会得到一个回复:`res.send(“something”); 但那只是在responseText中,isRejected是真的,所以......
任何想法?
更新
* 以下是截断的消息部分:*
"Object function () {
if (!wasApplied) {
Class.proto(); // prepare prototype...
}
o_defineProperty(this, GUID_KEY, undefinedDescriptor);
o_defineProperty(this, '_super', undefinedDescriptor);
var m = meta(this), proto = m.proto;
m.proto = this;
if (initMixins) {
// capture locally so we can clear the closed over variable
var mixins = initMixins;
initMixins = null;
this.reopen.apply(this, mixins);
}
if (initProperties) {
// capture locally so we can clear the closed over variable
var props = initProperties;
initProperties = null;
var concatenatedProperties = this.concatenatedProperties;
for (var i = 0, l = props.length; i < l; i++) {
var properties = props[i];
Ember.assert("Ember.Object.create no longer supports mixing in other definitions, use createWithMixins instead.", !(properties instanceof Ember.Mixin));
if (properties === null || typeof properties !== 'object') {
Ember.assert("Ember.Object.create only accepts objects.");
continue;
}
var keyNames = Ember.keys(properties);
for (var j = 0, ll = keyNames.length; j < ll; j++) {
var keyName = keyNames[j];
if (!properties.hasOwnProperty(keyName)) { continue; }
var value = properties[keyName],
IS_BINDING = Ember.IS_BINDING;
if (IS_BINDING.test(keyName)) {
var bindings = m.bindings;
if (!bindings) {
bindings = m.bindings = {};
} else if (!m.hasOwnProperty('bindings')) {
bindings = m.bindings = o_create(m.bindings);
}
bindings[keyName] = value;
}
var desc = m.descs[keyName];
Ember.assert("Ember.Object.create no longer supports defining computed properties.", !(value instanceof Ember.ComputedProperty));
Ember.assert("Ember.Object.create no longer supports defining methods that call _super.", !(typeof value === 'function' && value.toString().indexOf('._super') !== -1));
Ember.assert("`actions` must be provided at extend time, not at create time, when Ember.ActionHandler is used (i.e. views, controllers & routes).", !((keyName === 'actions') && Ember.ActionHandler.detect(this)));
if (concatenatedProperties && indexOf(concatenatedProperties, keyName) >= 0) {
var baseValue = this[keyName];
if (baseValue) {
if ('function' === typeof baseValue.concat) {
value = baseValue.concat(value);
} else {
value = Ember.makeArray(baseValue).concat(value);
}
} else {
value = Ember.makeArray(value);
}
}
if (desc) {
desc.set(this, keyName, value);
} else {
if (typeof this.setUnknownProperty === 'function' && !(keyName in this)) {
this.setUnknownProperty(keyName, value);
} else if (MANDATORY_SETTER) {
Ember.defineProperty(this, keyName, null, value); // setup mandatory setter
} else {
this[keyName] = value;
}
}
}
}
}
finishPartial(this, m);
this.init.apply(this, arguments);
m.proto = proto;
finishChains(this);
sendEvent(this, "init");
} has no method 'extract'"
UPDATE2:
发现你可以覆盖ajax方法。现在,至少我知道,json IS在成功函数上传输,但数据属性仍未定义......
App.ApplicationAdapter = DS.RESTAdapter.extend({
url: 'http://localhost:3000',
namespace: 'api',
ajax: function(url, type, hash) {
var adapter;
adapter = this;
return new Ember.RSVP.Promise(function(resolve, reject) {
var headers;
hash = hash || {};
hash.url = url;
hash.type = type;
hash.dataType = "json";
hash.context = adapter;
if (hash.data && type == "GET") {
hash.contentType = "application/json; charset=utf-8";
hash.data = JSON.stringify(hash.data);
}
if (adapter.headers !== undefined) {
headers = adapter.headers;
hash.beforeSend = function(xhr) {
return forEach.call(Ember.keys(headers), function(key) {
return xhr.setRequestHeader(key, headers[key]);
});
};
}
hash.success = function(json) {
console.log("success", hash.data, json); //-> undefined, Object {video: Object}
return Ember.run(null, resolve, json);
};
hash.error = function(jqXHR, textStatus, errorThrown) {
return Ember.run(null, reject, adapter.ajaxError(jqXHR));
};
return Ember.$.ajax(hash);
});
},
});
答案 0 :(得分:1)
如果您使用的是ember-data 1.0.0-beta.x版本,则需要声明您的适配器和序列化器,如下所示:
App.ApplicationSerializer = DS.RESTSerializer.extend({
primaryKey: '_id'
});
App.ApplicationAdapter = DS.RESTAdapter.extend({
url: 'http://mylocalhost:3000',
namespace: 'api'
});
App.VideoRoute = Ember.Route.extend({
model: function() {
console.log("video..", this.store.find('video'));
return true;
}
});
有一个转换指南here,它告诉我们0.13和1.0.0-beta.x版本之间的变化是什么