addon/list-utils.js
function normalizeItems ({data, labelAttribute, records, valueAttribute}) {
  const labelAttr = labelAttribute || 'label'
  const valueAttr = valueAttribute || 'id'

  return data.concat(
    records.map((record) => {
      if (typeof record !== 'object') {
        return {
          label: `${record}`, // make sure label is a string
          value: record
        }
      }

      let label, value

      if (labelAttr.indexOf('${') !== -1) {
        label = utils.parseVariables(record, labelAttr)
      } else {
        label = get(record, labelAttr) || get(record, 'title')
      }

      if (valueAttr.indexOf('${') !== -1) {
        value = utils.parseVariables(record, valueAttr)
      } else {
        value = get(record, valueAttr)
      }

      return {
        label,
        value
      }
    })
  )
}
function normalizeItems ({data, labelAttribute, records, valueAttribute}) {
  const labelAttr = labelAttribute || 'label'
  const valueAttr = valueAttribute || 'id'

  return data.concat(
    records.map((record) => {
      if (typeof record !== 'object') {
        return {
          label: `${record}`, // make sure label is a string
          value: record
        }
      }

      let label, value

      if (labelAttr.indexOf('${') !== -1) {
        label = utils.parseVariables(record, labelAttr)
      } else {
        label = get(record, labelAttr) || get(record, 'title')
      }

      if (valueAttr.indexOf('${') !== -1) {
        value = utils.parseVariables(record, valueAttr)
      } else {
        value = get(record, valueAttr)
      }

      return {
        label,
        value
      }
    })
  )
}
function normalizeItems ( { data , labelAttribute , records , valueAttribute } ) { const labelAttr = labelAttribute || 'label' const valueAttr = valueAttribute || 'id' return data . concat ( records . map ( ( record ) => { if ( typeof record !== 'object' ) { return { label : ` ${ record } ` , // make sure label is a string value : record } } let label , value if ( labelAttr . indexOf ( '${' ) !== - 1 ) { label = utils . parseVariables ( record , labelAttr ) } else { label = get ( record , labelAttr ) || get ( record , 'title' ) } if ( valueAttr . indexOf ( '${' ) !== - 1 ) { value = utils . parseVariables ( record , valueAttr ) } else { value = get ( record , valueAttr ) } return { label , value } } ) ) }
Converts records from an API response into a standard format with "label"
and "value" properties so renderers can predictably process the data.
@param {Object[]} data - initializes the list with this
@param {String} labelAttribute - dot notated path to label attribute in record
@param {Array<Object>} records - records to normalize
@param {String} valueAttribute - dot notated path to value attribute in record
@returns {Array<Object>} normalized items
Converts records from an API response into a standard format with label and value properties so renderers can predictably process the data .