当前位置: 首页 > 软件库 > 程序开发 > >

ember-data-copyable

授权协议 MIT License
开发语言 JavaScript
所属分类 程序开发
软件类型 开源软件
地区 不详
投 递 者 卓嘉良
操作系统 跨平台
开源组织
适用人群 未知
 软件概览

Ember Data Copyable

npm version

Intelligently copy an Ember Data model and all of its relationships

Features

  • Shallow & deep copy an Ember Data model
  • Shallow & deep copy model relationships
  • Handles cyclical relationships
  • Handles custom transforms to create true copies
  • Overwrite, ignore attributes, and copy objects by reference
  • Intelligent failure and cleanup
  • Uses ember-concurrency to allow cancelling a copy task

Installation

ember install ember-data-copyable

Helpful Links

Looking for help?

If it is a bug please open an issue on GitHub.

Setup

This addon provides a Copyable mixin which allows you to copy a model. To get started,just import the mixin and add it to your model.

// models/user.js

import DS from 'ember-data';
import Copyable from 'ember-data-copyable';

export default DS.Model.extend(Copyable, {
  guid: DS.attr('number'),
  firstName: DS.attr('string'),
  lastName: DS.attr('string'),
  address: DS.belongsTo('address'),
  friends: DS.hasMany('user'),

  // Specific copy options for the model
  copyableOptions: {}
});

In your model you can specify default options via the copyableOptions object.Please see options for more details.

Copying Relationships

To copy a model's relationship, that relational model must have the Copyable mixin or else it will justbe copied by reference.

Usage

Once the model is setup, we can use the copy method on an instance to duplicate it.

Copy Method Signature

async function copy(deep = false, options = {}) {}
  • deep : Boolean

    If false a shallow copy of the model's attributes will be created.All relationships will be copied over by reference.

    If true, a deep copy of the model and it's relationships will be created.If a relational model has the Copyable mixin, it will also be deep copied.

  • options : Object

    Copy options. See options for more details.

    NOTE: Options passed into the copy method take precedence over those specified on the model.

Returns a cancelable promise like ember-concurrency TaskInstance.

Examples

Normal Usage

const model = this.get('store').peekRecord('user', 1);

model
  .copy(true, {
    ignoreAttributes: ['guid'],
    copyByReference: ['address'],
    overwrite: {
      id: 2,
      firstName: 'Offir'
    }
  })
  .then(
    copy => {
      // Handle success
      return copy.save();
    },
    e => {
      // Handle error or cancellation
    }
  );

Task Cancellation

Since the copy method returns an ember-concurrency TaskInstance,we have the ability to cancel a running copy task at any time.

const model = this.get('store').peekRecord('user', 1);
const copyTaskInstance = model.copy(true);

// Cancel our copy task
copyTaskInstance.cancel();

Options

These options can either be specified via the copyableOptions object on the DS.Model class orpassed into the copy method.

ignoreAttributes

Attributes to ignore when copying.

ignoreAttributes: ['guid', 'address'];

otherAttributes

Other attributes to copy over that are not defined via DS.attr, DS.belongsTo,or DS.hasMany.

otherAttributes: ['timestamp', 'someFlag'];

copyByReference

Attributes to copy only by reference. If the attribute has the Copyable mixin, it willbe ignored and not be copied, just copied by reference.

copyByReference: ['friends'];

overwrite

Overwrite attributes with the specified values. This will also add propertiesthat are not found on the model.

overwrite: {
  id: 2,
  firstName: 'Offir - Copy',
  address: this.get('store').createRecord('address', { /* ... */ }),
  unknownProperty: 'Foo Bar'
}

relationships

Specify options to nested models.Nested relationships options can also include a deep option. If set to false,the relationship will be shallow copied.

relationships: {
  address: {
    ignoreAttributes: ['streetName'],
    overwrite: {
      state: 'CA'
    }
  },
  friends: {
    copyByReference: ['address']
  },
  profile: {
    deep: false
  }
}
  •         DataSet ds = new DataSet();         DataTable dt = ret.DataSet.Tables[0].Clone();         for (int i = 0; i < row.count; i++)         {                    DataRow dr = ret.DataSet.Tables[0].Ro

  • c# 复制datatable结构.clone() 复制datatable结构和数据.copy() DataTable.select("name like '%abc%'") DataTable.select("name ='abc'") DataTable.select("name >'abc'") 

  • sp_addumpdevice  将备份设备添加到 Microsoft SQL Server。  语法:   sp_addumpdevice [ @devtype = ] 'device_type' ,       [ @logicalname = ] 'logical_name' ,       [ @physicalname = ] 'physical_name'       [ , { [

 相关资料
  • ember-data-tasks An alternative Ember Data store that returns Ember Concurrency tasks instead of promises. Install ember install ember-data-tasks This addon comes in three phases: Phase 1: Store Overr

  • ember-data-contentful This is an Ember Data adapter/serializer that uses the READ ONLY Content Delivery API from contentful Setup in your app ember install ember-data-contentful After installing the a

  • Ember Data Github Ember Data abstraction for the GitHub REST API v3. Installation ember install ember-data-github Usage You need to choose how you wish to authenticate your GitHub requests using OAuth

  • 目前,我们的应用程序使用硬编码的数据作为租赁列表中定义的rentals路由处理程序。随着应用程序的发展,我们希望在服务器上保留我们的租用数据,并且更容易地对数据进行高级操作,如查询。 Ember提供了一个名为Ember Data的数据管理的库来帮助处理持久的应用程序数据。 Ember Data要求你通过扩展DS.Model来定义要提供给应用程序的数据的结构。 可以使用Ember CLI生成Embe

  • ember-data-url-templates ember-data-url-templates is an addon to allow building urls with url templates instead ofdefining buildURL as described in RFC #4. ember-data-url-templates is under early deve

  • Ember检查器是一个浏览器插件,用于调试Ember应用程序。 灰烬检查员包括以下主题 - S.No. 灰烬检查员方式和描述 1 安装Inspector 您可以安装Ember检查器来调试您的应用程序。 2 Object Inspector Ember检查器允许与Ember对象进行交互。 3 The View Tree 视图树提供应用程序的当前状态。 4 检查路由,数据选项卡和库信息 您可以看到检查