本文整理汇总了TypeScript中ember-data.JSONAPISerializer类的典型用法代码示例。如果您正苦于以下问题:TypeScript JSONAPISerializer类的具体用法?TypeScript JSONAPISerializer怎么用?TypeScript JSONAPISerializer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了JSONAPISerializer类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: serialize
import Ember from 'ember';
import DS from 'ember-data';
interface Dict<T> {
[key: string]: T | null | undefined;
}
const JsonApi = DS.JSONAPISerializer.extend({});
const Customized = DS.JSONAPISerializer.extend({
serialize(snapshot: DS.Snapshot<'user'>, options: {}) {
const lookup = snapshot.belongsTo('username');
let json: any = this._super(...Array.from(arguments));
json.data.attributes.cost = {
amount: json.data.attributes.amount,
currency: json.data.attributes.currency
};
return json;
},
normalizeResponse(store: DS.Store, primaryModelClass: DS.Model, payload: any, id: string|number, requestType: string) {
payload.data.attributes.amount = payload.data.attributes.cost.amount;
payload.data.attributes.currency = payload.data.attributes.cost.currency;
delete payload.data.attributes.cost;
return this._super(...Array.from(arguments));
}
});
示例2: keyForAttribute
import DS from 'ember-data';
export default DS.JSONAPISerializer.extend({
keyForAttribute(key: string) {
return key;
},
keyForRelationship(key: string) {
return key;
},
});