本文整理汇总了TypeScript中js-data.DS.defineResource方法的典型用法代码示例。如果您正苦于以下问题:TypeScript DS.defineResource方法的具体用法?TypeScript DS.defineResource怎么用?TypeScript DS.defineResource使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类js-data.DS
的用法示例。
在下文中一共展示了DS.defineResource方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: require
import * as JSData from 'js-data';
import DSHttpAdapter = require("js-data-http");
declare var axios: any;
var adapter = new DSHttpAdapter();
var store = new JSData.DS();
store.registerAdapter('http', adapter, { default: true });
adapter.defaults.basePath = '/api';
adapter.http = axios;
var ADocument: JSData.DSResourceDefinition<any> = store.defineResource<any>('document');
ADocument.inject({ id: 5, author: 'John' });
// bypass the data store
adapter.update(ADocument, 5, { author: 'Johnny' }).then((document: any) => {
document; // { id: 5, author: 'Johnny' }
// The updated document has NOT been injected into the data store because we bypassed the data store
ADocument.get(document.id); // { id: 5, author: 'John' }
});
// Normally you would just go through the data store
ADocument.update(5, { author: 'Johnny' }).then((document: any) => {
document; // { id: 5, author: 'Johnny' }
// the updated document has been injected into the data store
ADocument.get(document.id); // { id: 5, author: 'Johnny' }
});
示例2: function
useFactory: function(adapter:JSData.IDSAdapter) {
let ds = new JSData.DS();
ds.registerAdapter('GEAR_LIST_DATASTORE_ADAPTER', adapter, { default: true });
ds.defineResource({
name: 'function',
endpoint: 'functions',
relations: {
hasMany: {
item: {
localField: 'items',
foreignKey: 'function_id'
}
}
}
});
ds.defineResource({
name: 'list',
endpoint: 'lists',
relations: {
hasMany: {
pick: {
localField: 'picks',
foreignKey: 'list_id'
}
}
}
});
ds.defineResource({
name: 'pick',
endpoint: 'picks',
relations: {
hasOne: {
list: {
localField: 'list',
localKey: 'list_id'
},
item: {
localField: 'item',
localKey: 'item_id'
}
}
}
});
ds.defineResource({
name: 'item',
endpoint: 'items',
relations: {
hasOne: {
function: {
localField: 'function',
localKey: 'function_id'
}
}
}
});
return ds;
},