鉴于我有 Ember 数据模型(这是 CoffeeScript):
Person = DS.Model.extend
firstName: DS.attr("string")
lastName: DS.attr("string")
或作为 JavaScript:
Person = DS.Model.extend({
firstName: DS.attr("string"),
lastName: DS.attr("string")
});
如何使用 mockjax 从商店返回 Person 对象?这个 mockjax 不起作用(我认为),因为它返回一个匿名 JavaScript 对象,而不是 Person 对象。
$.mockjax
type: "GET"
url: "/people"
data: { firstName: "John"}
status: "200"
dataType: "json"
response: (d) ->
person =
{
id: 2
firstName: John
lastName: Smith
}
@responseText = person
或作为 JavaScript:
$.mockjax({
type: "GET",
url: "/people",
data: {
firstName: "John"
},
status: "200",
dataType: "json",
response: function(d) {
var person;
person = {
id: 2,
firstName: John,
lastName: Smith
};
return this.responseText = person;
}
});
我正在使用 ES6 仅供参考。