loio |
---|
ac56d92162ed47ff858fdf1ce26c18c4 |
view on: demo kit nightly build | demo kit latest release
Control properties are defined as follows:
properties: {
title : "string", // a simple string property, default value is undefined
buttonText : {defaultValue: "Search"}, // when no type is given, the type is string
showLogoutButton : {type : "boolean", defaultValue : true}, // a boolean property where a default value is given
width : {type : "sap.ui.core.CSSSize", defaultValue : "50px"} // a CSS size property where a default value is given
}
After the property is defined, the control automatically has the setShowLogoutButton
and getShowLogoutButton
methods for storing data. It is possible to assign custom definitions to these methods by overriding them and calling the generic property methods setProperty
and getProperty
:
MyControl.prototype.setShowLogoutButton = function(show) {
this.setProperty("showLogoutButton", show); // this validates and stores the new value
return this; // return "this" to allow method chaining
};
Built-in Types
Type |
Description |
---|---|
|
Can either be |
|
JavaScript primitive values of type |
|
JavaScript primitive values of type |
|
JavaScript string literal ( |
|
Plain JavaScript object (an object whose constructor is Don't mix this type up with the |
|
Any valid Javascript value (including primitives, objects, functions, regular expressions, and native objects). The support in serialized formats is quite limited. Valid JSON strings will be deserialized to an object. The default value is |
|
Can be any JavaScript function.
|
Derived Types
Category |
Description |
---|---|
regular expression (RegExp) |
Derived from the built-in type Restricted subtypes that limit their valid values to strings that match a given regular expression.
Example:
If For more information, see the API Reference. |
enumeration (enum) |
Derived from the built-in type Restricted subtypes can be derived that limit their valid values to a fixed set of values (enumeration). An Restrictions:
This was an early design decision in OpenUI5 and framework code relies on it. That code might fail for enumerations that don't obey these restrictions. To reference an Example for creating an enumeration: sap.ui.define(["sap/ui/base/DataType"], (DataType) => {
/**
* Enumeration of possible value color settings.
*
* @enum {string}
* @public
*/
const ValueColor = {
/**
* Neutral value color.
* @public
*/
Neutral : "Neutral",
…
};
// Register enum type
DataType.registerEnum("sap.m.ValueColor", ValueColor);
}); Example for defining a property using an enumeration: properties: {
myProperty : {type: "sap.m.ValueColor", defaultValue: "Neutral"}
} Example for requiring enum types programmatically: sap.ui.require([
"sap/m/library", // enum sap.m.ButtonType (Module: sap/m/library)
"sap/ui/model/FilterType" // enum sap.ui.model.FilterType (Module: sap/ui/model/FilterType)
], (sapMLib, FilterType) => {
const { ButtonType } = sapMLib;
mySapMButton.setType(ButtonType.Emphasized);
myListBinding.filter(myFilter, FilterType.Control);
}); Make sure to check the API Reference on how to access types via their correct Module IDs (documented as "Module: .../.../...").
|
array |
You don't have to define array types before using an array. From each valid type above, an array type with one or more dimensions can be derived by simply appending a pair of square brackets ( Example: properties: {
myProperty1 : "int[]",
myProperty2 : "int[][]"
}
The type of an element in an array is called the component type ( The The default value for any array type is the empty array. |
At runtime, each type is represented as instance of the class DataType
(sap/ui/base/DataType.js
). A type can be looked up by its name by calling DataType.getType(name)
. The framework treats all values for the above types as if they would be atomic. Changes inside a value (e.g. changing the property of a value of type object
or adding, removing, or changing members of an array) are not detected by the framework and might lead to unexpected results. Instead, any change should be applied by setting a new (or modified) value with a call like setText
, setCaption
, setColor
.
Related Information