dictionary.wxs 635 B

1234567891011121314151617181920212223
  1. function getDictionaryOptions() {
  2. if (arguments.length !== 2) return [];
  3. var keys = arguments[0].map(function (item) { return item.key; });
  4. var index = keys.indexOf(arguments[1]);
  5. return index !== -1 ? arguments[0][index].options : []
  6. };
  7. function getDictionaryLabel() {
  8. if (arguments.length !== 3) return '';
  9. var options = getDictionaryOptions(arguments[0], arguments[1]);
  10. var keys = options.map(function (item) { return item.value; });
  11. var index = keys.indexOf(arguments[2]);
  12. return index !== -1 ? options[index].label : ''
  13. };
  14. module.exports = {
  15. options: getDictionaryOptions,
  16. label: getDictionaryLabel
  17. };