本文整理匯總了TypeScript中js-data.DS類的典型用法代碼示例。如果您正苦於以下問題:TypeScript DS類的具體用法?TypeScript DS怎麽用?TypeScript DS使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了DS類的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;
},