递归js函数简化列表结果

时间:2018-03-26 10:39:29

标签: javascript recursion

我正在尝试创建一个递归函数,它将简化和修剪已接受的文件扩展名列表

所以我的第一个输入看起来像这样

spinner.setOnItemSelectedListener(
            new AdapterView.OnItemSelectedListener() {
                int prev = comboValues.getSelectedItemPosition();
                @Override
                public void onItemSelected(AdapterView<?> parentView, View selectedItemView, int position, long id) {
                                            prev=position;
                }

                @Override
                public void onNothingSelected(AdapterView<?> parentView) {


                }

            }
    );

我的第二个看起来像这样

"application/pdf, application/x-pdf, application/acrobat, applications/vnd.pdf, text/pdf, text/x-pdf, application/ppt, application/vnd.ms-powerpoint"

然后我想最终得到像这样的输出

"pdf", "x-pdf", "vnd.pdf", "pdf", "x-pdf", "ppt"

http://jsfiddle.net/pg886/136/

"pdf", "ppt"

1 个答案:

答案 0 :(得分:1)

这样的东西?

let childItems: MenuItem[] = [];
for (let j = 0; j < ejsItem.length; j++) {
    if (ejsItem[j].codeBusinessGroup == groupsItem[i].code) {
        childItems.push({ label: ejsItem[j].name }) // items to add them as sub-menu
    }
}
this.items[i].items = childItems;