Skip to content

Instantly share code, notes, and snippets.

@jaydenlin
Created December 8, 2020 19:01
Show Gist options
  • Save jaydenlin/75da85560f89a11c88a42de902d48586 to your computer and use it in GitHub Desktop.
Save jaydenlin/75da85560f89a11c88a42de902d48586 to your computer and use it in GitHub Desktop.
getCheckedKeys.js
const parseTagId = (key) => {
//取 tag_588 中的 tag id 數字
return key.match(/\d+/g) === null ? null: key.match(/\d+/g)[0];
}
const isTagKey = (key) => {
//判斷是不是 tag (資料夾會是undefined) 以及是否可以取 tag id
return typeof key !== "undefined" && parseTagId(key) !== null;
}
const getCheckedKeys = () => {
const dataKeys = this.$refs['tree'].getCheckedKeys();
//
this.tag_ids = dataKeys.filter((key)=>{
return isTagKey(key); // 篩選取 tag
}).map((key)=>{
return parseTagId(key);// 爬出 tag id 回傳
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment