Docs (4.0.0)
Bindings

class StringFormatBinding

A class that represents a string-formatted binding with nested property bindings.

class StringFormatBinding<S extends string = string>
extends Binding<LazyString>

Description

String-formatted bindings use a ‘format string’ that contains one or more placeholders, along with a set of associated (nested) bindings. They can be used just like regular property bindings (see Binding).

After binding to an object, the underlying string value is updated whenever any of the nested bindings change — inserting the bound values into the string.

Instances of this class can be created using the bound.strf function.

Examples

// String-formatted bindings with positional arguments
bound.strf("Today is %s", "dayOfTheWeek")
bound.strf("%i table row#{/s}, total %.2f", "rows.length", "calcTotal")
// String-formatted binding with object argument
bound.strf(
  "%[user] is %[age] years old",
  {
    user: bound("user.name", strf("Unknown user")),
    age: bound.number("user.age").else(99)
  }
)
// A label with bound text
// (Note: JSX element text is bound automatically, see `JSX`)
ui.label(
  bound.strf("Welcome, %s", "user.fullName")
)

Constructor

Instance Members

  • toString()Returns a description of this binding, including its original format string.

Inherited Members

  • bindTo(target, propertyOrFunction)Applies this binding to the specified target object.
  • asString(format?)Adds a filter, to convert the bound value to a string.
  • asNumber()Adds a filter, to convert the bound value to a number.
  • asList()Adds a filter, to make sure that the bound value is an iterable list.
  • asBoolean()Adds a filter, to convert the bound value to a boolean.
  • not()Adds a filter, to convert the bound value to a boolean, and negate it.
  • strf(format)Adds a filter, to include the bound value in a formatted string.
  • local(…type)Adds a filter, to use the current I18n provider to localize the bound value.
  • select(trueValue, falseValue?)Adds a filter, to use one of the provided values instead of the bound value.
  • else(falseValue)Adds a filter, to use the provided value instead of a bound value that’s equal to false.
  • matches(…values)Adds a filter, to compare the bound value and replace it with true or false.
  • equals(source)Adds a filter, to compare the bound value with another bound value.
  • and(source)Adds a filter, to perform a logical AND (i.e. &&) operation with another binding.
  • or(source)Adds a filter, to perform a logical OR (i.e. ||) operation with another binding.
  • debug()Adds a filter, to emit an event whenever the bound value changes.
  • clone() protectedReturns a copy of this object.
  • isBindingA method that’s used for duck typing, always returns true.
  • [BindingOrValue.TYPE_CHECK]A method that’s used for type checking, doesn’t actually exist.