fcf.resolveEx() function
{object , key } fcf.resolveEx (object a_obj, string |[string |object ] a_path, boolean a_createObj = false)
Package: fcf-framework-core
File: fcf-framework-core:fcf.js
Available from version: 2.0.2
Returns information about the subobject at the given path, and optionally creates subobjects at the specified path if it is not present in the source object.
Arguments
- Source object
- The path to the subfield to extract. See the path format in the description of the function fcf.parseObjectAddress
- If true , then if the subobject in which the subfield is searched is not found, then a field of the corresponding type will be created (an array or an object, as specified in the path parameters).
Result
{object , key }
- Returns an object with information about the selected field
Object properties:
object object - The object containing the found subfieldstring object - Object containing found subfield
If an object containing the given field is not found and the
Example: Function application
{
let object = {
field1: {
field2: "value",
}
}
let ref = fcf.resolveEx(object, "field1.field2");
console.log(ref.object[ref.key]);
}
Output:
value
Example: Subfield creation mode
{
let object = {}
let ref = fcf.resolveEx(object, "field1.field2", true);
console.log("Reference:", ref);
console.log("Source:", object);
}
console.log("");
console.log("Creating an array");
{
let object = {}
let ref = fcf.resolveEx(object, "[[field1]].field2", true);
console.log("Reference:", ref);
console.log("Source:", object);
}
Output:
Reference: { key: 'field2', object: {} }
Source: { field1: {} }
Creating an array
Reference: { key: 'field2', object: [] }
Source: { field1: [] }