Git Product home page Git Product logo

tree-lodash's Introduction

Hi there 👋

zhangshichun's GitHub stats 掘金账号:摸鱼的春哥

tree-lodash's People

Contributors

chensuiyi520 avatar zhangshichun avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

tree-lodash's Issues

请求增加功能

我需要下面这3个功能:
export class Tree {
/**从当前元素开始(包含),向上冒泡,直到指定的祖先元素(不包含),每个元素都执行一次回调,如果回调返回true,则终止冒泡。*/
static bubbleCall(node: any, callback: (node: any) => boolean, parent: any): any {
if (node === parent || callback(node))
return node;
return Tree.bubbleCall(node.parentElement, callback, parent);
};

/**从当前元素开始(包含),向上冒泡,直到指定的祖先元素(不包含),找到第一个符合要求的元素,执行回调,并返回回调结果。*/
static onClosest<TNode extends {parentElement:TNode}>(currentNode: TNode, predict: (node: TNode) => boolean, callback: (node: TNode) => TNode, parent: TNode): TNode | undefined {
if (predict(currentNode))
return callback(currentNode);
if (currentNode !== parent && currentNode.parentElement)
return Tree.onClosest(currentNode.parentElement, predict, callback, parent);
};

//static toArray(){
//
//}

/** array 组装成树 */
static array2tree(array,idStr='id',parentStr='parent',rootStr=1){
let group = {};
array.forEach(node=>{
let parent = group[node[parentStr]] = group[node[parentStr]] || [,[]];
parent[1].push(node);
let self = group[node[idStr]] = group[node[idStr]] || [,[]];
node.children = self[1];
self[0] = node;
})
return group[rootStr][0];
}
}
大佬能不能加到库中?

调用map,返回新的树节点异常,缺少字段

const formatTree = window.treeLodash.map(treeData, (node, meta) => {
    return {
      id: node.dicId,
      name: node.name,
      code: node.code,
      pcode: node.pcode,
      dicCode: node.dicCode,
      depth: meta.depth,
      children: node.list,
    };
  }, {
    childrenKey: 'list'
  });

使用类似结构调用map方法,返回的新的树节点对象会同时包含list和children两个key,list中的子节点返回正常,但是children中的子节点缺少children字段 (children: node.list 未生效)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.