MCPcopy Create free account
hub / github.com/MankaiHuang/screen-visualization / findTemplateForId

Function findTemplateForId

public/iframe/lib/js/commonFun.js:119–145  ·  view source on GitHub ↗
(id, templateList = this.templateList)

Source from the content-addressed store, hash-verified

117 }
118 },
119 findTemplateForId(id, templateList = this.templateList) {
120 // 因为存在children的情况 因此这里要遍历所有元素去查找
121 const nowTemplate = []
122 const find = (node) => { // 匿名函数防止this指向错误
123 node.some(item => {
124 const { type, componentsType, option, children, elementId } = item.property
125 if (type !== 'group') {
126 if (elementId === id) {
127 nowTemplate.push(item);
128 return true
129 }
130 if (componentsType === "private") {
131 // 如果是私有组件 则取 option.templatelist
132 find(option.templateList)
133 }
134 }
135 if (type === 'group' && children.length > 0) {
136 find(children)
137 }
138
139 })
140 }
141 find(templateList)
142 if (nowTemplate.length > 0) {
143 return nowTemplate[0]
144 }
145 },
146 GetQueryString(name, url) {
147 // 获取url中指定参数的值
148 const reg = new RegExp(`(^|&)${name}=([^&]*)(&|$)`);

Callers

nothing calls this directly

Calls 1

findFunction · 0.70

Tested by

no test coverage detected