当前位置: 首页>>代码示例>>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;未经允许,请勿转载。