docs/api/datarecord.md
The DataRecord class represents a single record within a data source.
It extends the base Model class and provides additional methods and properties specific to data records.
Each DataRecord is associated with a DataSource and can trigger events when its properties change.
const record = new DataRecord({ id: 'record1', name: 'value1' }, { collection: dataRecords });
const path = record.getPath(); // e.g., 'SOURCE_ID.record1'
record.set('name', 'newValue');
props DataRecordProps Properties to initialize the data record.opts Object Options for initializing the data record.Get the path of the record. The path is a string that represents the location of the record within the data source. Optionally, include a property name to create a more specific path.
prop String? Optional property name to include in the path.
opts Object? Options for path generation.
opts.useIndex Boolean? Whether to use the index of the record in the path.const pathRecord = record.getPath();
// e.g., 'SOURCE_ID.record1'
const pathRecord2 = record.getPath('myProp');
// e.g., 'SOURCE_ID.record1.myProp'
Returns String The path of the record.
Get both ID-based and index-based paths of the record. Returns an array containing the paths using both ID and index.
prop String? Optional property name to include in the paths.const paths = record.getPaths();
// e.g., ['SOURCE_ID.record1', 'SOURCE_ID.0']
Returns Array<String> An array of paths.
Trigger a change event for the record. Optionally, include a property name to trigger a change event for a specific property.
prop String? Optional property name to trigger a change event for a specific property.Set a property on the record, optionally using transformers. If transformers are defined for the record, they will be applied to the value before setting it.
attributeName (String | Object) The name of the attribute to set, or an object of key-value pairs.
value any? The value to set for the attribute.
options Object? Options to apply when setting the attribute.
options.avoidTransformers Boolean? If true, transformers will not be applied.record.set('name', 'newValue');
// Sets 'name' property to 'newValue'
Returns DataRecord The instance of the DataRecord.