new pages.dt/js/api/Properties(propertyMapopt)
stable API
Holds View's properties. A view keeps its properties in a Properties object which is usually accessed by a property inspector for modifications and by a Generator to build a specific DOM element according to the property values.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
propertyMap |
Object |
<optional> |
key-value pair map of property names and values. If defined the newly created instance will be initialized with keys and values from the map. |
- Version:
- 16.3.5
- Source:
- See:
-
- View.getProperties to get view's properties object
Example
var map = {
myProp1: 'value 1',
myProp2: 'value 2'
};
// create a initialized instance
var properties = new Properties(map);
// will yield 'value 1'
properties.getValue('myProp1');
// updated the stored value
properties.setValue('myProp1', 'modification');
// returns updated value: 'modification'
properties.getValue('myProp1');
Methods
getDefinition() → {Object}
stable API
Gets the serialized Properties object (as JSON).
Serialized version of the Properties object is a simple hash map containing all properties's key-value entries which can be used also in the Properties constructor for creation of a new instance (that leads to the properties's clone).
- Version:
- 16.3.5
- Source:
- See:
-
- Properties.constructor which accepts the definition object
Returns:
JSON holding all properties's key-value entries
- Type
- Object
Example
// exports properties as maps
var definition1 = properties1.getDefinition();
var definition2 = properties2.getDefinition();
// uses jquery framework to merge the JSON objects
var mergedDefinition = $.extend({}, definition1, definition2);
// creates new properties with all values
var mergedProperties = new Properties(mergedDefinition);
getValue(key) → {*}
stable API
Returns the value stored in the properties
object under the given key or undefined
if the key does not exist.
Parameters:
Name | Type | Description |
---|---|---|
key |
String | property name |
- Version:
- 16.3.5
- Source:
- See:
-
- Properties.setValue which sets values for keys
Returns:
property value, may be undefined
if such key doesn't exist
- Type
- *
Example
// creation of the new properties object
var properties = new Properties({
'firstProperty': 'hello',
'secondProperty': 'world'
});
// will yield 'hello world'
var welcomeText = properties.getValue('firstProperty')
+ ' ' + properties.getValue('secondProperty');
// will yield 'undefined' value
properties.getValue('nonExistingValue');
setValue(key, value) → {*}
stable API
Puts the passed value into the properties object
under the given key. The method returns the old value for the key or undefined
if the key didn't exist yet.
You should not call this method inside a Generator. Setting a property value may trigger another page rebuild and a subsequent call to your Generator, so you may introduce an endless loop.
Parameters:
Name | Type | Description |
---|---|---|
key |
String | property name used for properties entry identification |
value |
String | translations/js/api/Translatable | property value to be set into the properties entry |
- Version:
- 16.3.5
- Source:
- See:
-
- Properties.getValue which gets values for keys
Returns:
old property value or undefined
if the key didn't exist yet
- Type
- *
Example
// creation of the new properties object
var properties = new Properties({
'firstProperty': 'hello'
});
// will yield undefined as the previous value
properties.setValue('secondProperty', 2);
// will yield 'hello'
properties.getValue('firstProperty');
// will overwrite the 'firstProperty' with the value 'bye'
var formerValue = properties.setValue('firstProperty', 'bye');
console.log('Previous \'firstProperty\' value was \'' + formerValue + '\'.');