valueUtil.js 1.0 KB

1234567891011121314151617181920212223242526272829303132333435
  1. export var toArray = function toArray(value) {
  2. return Array.isArray(value) ? value : value !== undefined ? [value] : [];
  3. };
  4. export var fillFieldNames = function fillFieldNames(fieldNames) {
  5. var _ref = fieldNames || {},
  6. label = _ref.label,
  7. value = _ref.value,
  8. children = _ref.children;
  9. return {
  10. _title: label ? [label] : ['title', 'label'],
  11. value: value || 'value',
  12. key: value || 'value',
  13. children: children || 'children'
  14. };
  15. };
  16. export var isCheckDisabled = function isCheckDisabled(node) {
  17. return !node || node.disabled || node.disableCheckbox || node.checkable === false;
  18. };
  19. export var getAllKeys = function getAllKeys(treeData, fieldNames) {
  20. var keys = [];
  21. var dig = function dig(list) {
  22. list.forEach(function (item) {
  23. var children = item[fieldNames.children];
  24. if (children) {
  25. keys.push(item[fieldNames.value]);
  26. dig(children);
  27. }
  28. });
  29. };
  30. dig(treeData);
  31. return keys;
  32. };
  33. export var isNil = function isNil(val) {
  34. return val === null || val === undefined;
  35. };