Skip to content

Instantly share code, notes, and snippets.

@mactive
Created June 9, 2017 07:28
Show Gist options
  • Save mactive/6f35ced9b39dbabfd8d5d34d9ba10737 to your computer and use it in GitHub Desktop.
Save mactive/6f35ced9b39dbabfd8d5d34d9ba10737 to your computer and use it in GitHub Desktop.
recursion
/**
* 获取品类树 并 做key-value 映射
*/
getCascaderTree: function(){
var self = this;
// 递归 key-value 映射
var recursion = function(children){
if(children && children.length > 0){
return children.map((item)=>{
return {
label: item.name,
value: item.id,
children: recursion(item.subcate)
}
})
}else{
return [];
}
}
$.get('/uicomponent/wmpoi/cates', {},
function (res) {
if (res.code == 0) {
let _tagFriData = recursion(res.data);
self.setState({cascaderInfo: _tagFriData});
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment