The two-way-binding util is all about making query parameters that are bound to their objects that they describe. For example if you desire to have a model within a query parameter, you need to make sure that you only have the id in the url, but actually have access to the full model that belongs to that id within the controller. Two way bindings makes this process much easier. For more information on query parameters in general, click here. These two way bindings are specfically designed for moment objects or Ember models. Note: this function will go on the "id" field being displayed in the URL, and if either key or model is changed, both are changed properly. Each of the "methods" in this documentation are actually different computed properties you are able to import.

Import Syntax:

import {functionName} from '@bennerinformatics/ember-fw/utils/two-way-bindings';

//where functionName is the name of the function, so for example, the "momentToString" function would have the following syntax
import {momentToString} from '@bennerinformatics/ember-fw/utils/computed';
Show:
modelsToIds
(
  • modelsKey
  • optionsKey
)
Computed

Two-way binding between an array of model IDs and an array of model objects.

Usage Example:

// The actual model array, which is set as the "selected" attribute of the power-select-multiple or something similar
  selectedModels: [],
  
  // The array of model IDs, which will be used in the URL
  selectedModelIds: modelsToIds('selectedModels', 'model.options')
  

Parameters:

  • modelsKey String

    Key of the model array

  • optionsKey String

    Key of the model options array (the full list of models that are the options for the power-select-multiple)

Returns:

Computed:

Computed property

modelToId
(
  • modelKey
  • optionsKey
)
Computed

Two way binding between a model and a value in a model array. Set this function to the query parameter value:

Usage Example:

//the actual model, which is set as the "selected" attribute of the power-select or something similar
  locationModel: null,
  
  //note: model.locations is the array of location models, which is set as the "options" attribute of the power-select or something similar
  //the model id, which will be used in the url
  locationId: modelToId('locationModel', 'model.locations')
  

Parameters:

  • modelKey String

    Key of the model itself

  • optionsKey String

    Key of the model options array (ie the full list of models that are the options for the power select)

Returns:

Computed:

Computed property

momentToString
(
  • momentKey
  • format='YYYY-MM-DD HH:mm:ss'
)
Computed

Two way binding between a moment object and a query param string. This goes on the query parameter to show the date in the url.

Usage Example:

//actual moment object set by bs-datetimepicker or something similar
  start: null,
  
  //moment string to be displayed in the url
  startString: momentToString('start', 'YYYY-MM-DD'),
  

Parameters:

  • momentKey String

    Key of the moment object

  • [format='YYYY-MM-DD HH:mm:ss'] String optional

    Format to use for the moment string

Returns:

Computed:

Computed property