valueUtil.js 1.0 KB

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