//by 群ID:无名人氏 QQ:1107677019
function unique(arr) {
    var sortArr = arr.sort();
    var result = [sortArr[0]];
    var sortArrLen = sortArr.length;
    for (var i = 1; i < sortArrLen; i++) {
        sortArr[i] !== sortArr[i - 1] && result.push(sortArr[i]);
    }
    return result;
}

function getChildItems(selectedCompItems) {
    var selectedCompsNum = selectedCompItems.length;
    var childItems = {};
    var childLayersArr = [];
    var childCompItemsArr = [];
    function getChildCompItems(compItem) {
        var childLayersNum = compItem.layers.length;
        for (var i = 1; i <= childLayersNum; i++) {
            var currentLayer = compItem.layer(i);
            var currentLayerSource = currentLayer.source;
            if (currentLayerSource instanceof CompItem) {
                childCompItemsArr.push(currentLayerSource);
                getChildCompItems(currentLayerSource);
            } else {
                childLayersArr.push(currentLayer);
            }
        }
    }
    for (var i = 0; i < selectedCompsNum; i++) {
        getChildCompItems(selectedCompItems[i]);
    }
    childItems.compItems = unique(childCompItemsArr);
    childItems.layers = unique(childLayersArr);
    return childItems;
}

Leave a Reply

Your email address will not be published.