當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript js-data.DS類代碼示例

本文整理匯總了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' }
});
開發者ID:EmmaRamirez,項目名稱:DefinitelyTyped,代碼行數:31,代碼來源:js-data-http-tests.ts

示例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;
      },
開發者ID:gotascii,項目名稱:gear_list_browser_client,代碼行數:62,代碼來源:app.component.ts


注:本文中的js-data.DS類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。