DoneJS StealJS jQuery ++ FuncUnit DocumentJS
3.0.0
2.3.27

 

  • Github
  • Twitter
  • Chat
  • Forum
  • Guides
  • Core
    • can-component
    • can-compute
    • can-connect
      • behaviors
        • ./base/
        • ./cache-requests/
        • ./can/map/
        • ./can/ref/
        • ./constructor/callbacks-once/
        • ./constructor/
        • ./constructor/store/
        • ./data/callbacks/
        • ./data/callbacks-cache/
        • ./data/combine-requests/
        • ./data/localstorage-cache/
        • ./data/memory-cache/
        • ./data/parse/
        • ./data/url/
        • ./data/worker/
        • ./fall-through-cache/
        • ./real-time/
      • modules
        • ./can/base-map/
        • ./can/model/
        • ./can/super-map/
        • ./can/tag/
        • ./helpers/weak-reference-map
      • data types
        • DataInterface
          • clear
          • createData
          • destroyData
          • getData
          • getListData
          • getSets
          • updateData
          • updateListData
        • Instance
        • InstanceInterface
        • List
        • ListData
    • can-define
    • can-define/list/list
    • can-define/map/map
    • can-route
    • can-route-pushstate
    • can-set
    • can-stache
    • can-stache/helpers/route
    • can-stache-bindings
  • Ecosystem
  • Infrastructure
  • Legacy
  • Bitovi
    • Bitovi.com
    • Blog
    • Consulting
    • Training
    • Open Source
  • Chat
  • Forum
  • Star
  • Follow @canjs
  • CanJS
  • /
  • Core
  • /
  • can-connect
  • /
  • DataInterface
  • /
  • createData
  • / On this page
    • createData

      typedef

      Creates a new record in the connection.

      • source

      function(instanceData, cid)

      Creates a new record given the serialized form of the data. Resolves to a promise with any additional properties that should be added to the instance. A client ID is passed of the instance that is being created.

      The following shows how can-connect/constructor/constructor calls createData and what it does with the response:

      var CID = require("can-util/js/cid/cid");
      
      // Create an instance of a special type
      var myInstance = new MyType({ ... });
      
      // get it's CID
      var cid = CID(myInstance);
      
      // get its raw data
      var instanceData = connection.serializeInstance(myInstance);
      
      connection.createData(instanceData, cid).then(function(createdInstanceData){
          connection.createdInstance(myInstance, createdInstanceData);
      })
      

      Parameters

      1. instanceData {Object}:

        The serialized data of the instance.

      2. cid {Number}:

        A unique id that represents the instance that is being created. Given this value, the instance can be retrieved in the cidStore.

      Returns

      {Promise<Object>}:

      A promise resolved with the created data of the newly created instance. The created data must have the id of the created record.

      By default, createdInstance only adds the data in createdInstanceData to myInstance, it does not remove it. To remove "missing" properties on myInstance that are not in createdInstanceData, overwrite createdInstance.

      CanJS is part of DoneJS. Created and maintained by the core DoneJS team and Bitovi. Currently 3.0.0.