Field - callback (knowledge graph)

Description

Callback function applied to fields before rendering them.

The function requires four arguments:

  • type - type of entity, ie. person, document

  • fieldType - type of template field field; available field types:

    • title

    • subtitle

    • desc

    • detailPrimary

    • detailSecondary

    • listPrimary

    • listSecondary

  • fieldKey - metadata class name used to provide the field value for field types detail* and list*, for other types it is null

  • fieldValue - array of values

The function requires to return array of value/values.

Default value

field: {
  callback: null
}

Examples

Return only first value

field: {
  callback: function(type, fieldType, fieldKey, fieldValue) {
    return [fieldValue[0]];
  }
}

Return only first value for field types title, subtitle or desc

field: {
  callback: function(type, fieldType, fieldKey, fieldValue) {
  	const fieldTypes = ['title', 'subtitle', 'desc'];
    return fieldTypes.indexOf(fieldType) ? [fieldValue[0]] : fieldValue;
  }
}

Return correct case for metadata class State meaning instead of indexed value of act display in widget ACT

field: {
  callback: function(type, fieldType, fieldKey, fieldValue) {
    if (fieldKey === 'State') {
      for (var i = 0, len = fieldValue.length; i < len; i++) {
        fieldValue[i] = fieldValue[i].toUpperCase();
      }
    }
    return fieldValue;
  }
}