Created
June 9, 2017 07:28
-
-
Save mactive/6f35ced9b39dbabfd8d5d34d9ba10737 to your computer and use it in GitHub Desktop.
recursion
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 获取品类树 并 做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