dictionary.wxs 696 B

123456789101112131415161718192021222324
  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 v_l = arguments[2] ? arguments[2].split(':') : [];
  12. var index = keys.indexOf(v_l[0]);
  13. return index !== -1 ? v_l[1] || options[index].label : ''
  14. };
  15. module.exports = {
  16. options: getDictionaryOptions,
  17. label: getDictionaryLabel
  18. };