A5.uresolve Method
Syntax
Arguments
- valueany
The value to resolve.
- defaultValueany
The default value to use if no value can be resolved.
- dataobjectarray
The data for the current value to be resolve in.
- tempobject
The temporary object for the current value to be resolve in.
- scopeobject
The scope object for the current value to be resolve in.
- settingsobject
The settings object.
- templateobject
The template settings object.
- allowboolean
If true then a string value will be assumed to be a template and be expanded by the A5.u.template.expand method.
- pathstring
The path to store a parsed version of the template in. A prefix of "[temp]." or "[scope]." can be used to store the parsed template in the temp or scope objects. Otherwise the parsed template will be stored in the data.
Description
Resolve a value.
Discussion
The A5.u.resolve method can be used to resolve an arbitrary value down to a final useable value. This can be useful if a value may sometimes (bu not always) be a function or template and thus created dynamically. The value is passed to the resolve method along with a default value (if a value cannot be resolved from the passed in value). A data, temp and scope objects are pass in to provide data for templates or functions.
If templates are allowed, a path to a place to store the parsed template in the data, temp or scope objects can be defined. This is useful if the resolved value is a template and will be accessed multiple times. The stored parsed template means that the template only needs to be parsed once and all subsequent uses of the template will not require parsing.
Example
var data = [ {firstname: 'Bob', lastname: 'Smith'}, {firstname: 'Tom', lastname: 'Baker'} ]; var temp = {}; var scope = {}; var settings = { template: { allow: true, path: '[temp].nameTemp' } } var value = 'Hello {firstname} {lastname}'; var res = A5.u.resolve(value,'',data[0],temp,scope,settings); // res = "Hello Bob Smith" // temp.nameTemp = parsed template object res = A5.u.resolve(value,'',data[1],temp,scope,settings); // res = "Hello Tom Baker"