Javascript 无法在具有typescript的对象中设置属性 导出函数集合属性(元素:元素):属性接口{ 返回Array.from(element.attributes,({name,value})=>[ 名称 价值 ]).reduce((a,[key,val])=>{ if(关键字包括(“@”)){ 让handlerName=key.replace(“@”和“”) a、 handlers.push([handlerName,val]) }else if(key.startsWith(“s:”)){ 让styleProp=key.replace(“s:,”) a、 bindedStyle.push([styleProp,val]) }else if(key.startsWith(“c:”)){ 让classProp=key.replace(“c:,”); a、 bindedClasses.push([classProp,val]) }else if(key.startsWith(“a:”)){ 让attributeProp=key.replace(“a:,”); a、 BindeAttr.push([attributeProp,val]) }else if(键==“if”){ a、 show=val }else if(key.startsWith(“p:”)){ 让prop=key.replace(“p:,”); a、 props[prop]=val/
我已经修复了它: 我已将AttributesInterface添加到reduce函数的累加器中Javascript 无法在具有typescript的对象中设置属性 导出函数集合属性(元素:元素):属性接口{ 返回Array.from(element.attributes,({name,value})=>[ 名称 价值 ]).reduce((a,[key,val])=>{ if(关键字包括(“@”)){ 让handlerName=key.replace(“@”和“”) a、 handlers.push([handlerName,val]) }else if(key.startsWith(“s:”)){ 让styleProp=key.replace(“s:,”) a、 bindedStyle.push([styleProp,val]) }else if(key.startsWith(“c:”)){ 让classProp=key.replace(“c:,”); a、 bindedClasses.push([classProp,val]) }else if(key.startsWith(“a:”)){ 让attributeProp=key.replace(“a:,”); a、 BindeAttr.push([attributeProp,val]) }else if(键==“if”){ a、 show=val }else if(key.startsWith(“p:”)){ 让prop=key.replace(“p:,”); a、 props[prop]=val/,javascript,typescript,Javascript,Typescript,我已经修复了它: 我已将AttributesInterface添加到reduce函数的累加器中 export function collectAttributes(element: Element): AttributesInterface { return Array.from(element.attributes, ({ name, value }) => [ name, value, ]).reduce((a, [key, val])
export function collectAttributes(element: Element): AttributesInterface {
return Array.from(element.attributes, ({ name, value }) => [
name,
value,
]).reduce((a, [key, val]) => {
if (key.includes("@")) {
let handlerName = key.replace("@", "")
a.handlers.push([handlerName, val])
} else if (key.startsWith("s:")) {
let styleProp = key.replace("s:", "")
a.bindedStyle.push([styleProp, val])
} else if (key.startsWith("c:")) {
let classProp = key.replace("c:", "");
a.bindedClasses.push([classProp, val])
} else if (key.startsWith("a:")) {
let attributeProp = key.replace("a:", "");
a.bindedAttr.push([attributeProp, val])
} else if (key === "if") {
a.show = val
} else if (key.startsWith("p:")) {
let prop = key.replace("p:", "");
a.props[prop] = val // <------ HERE
} else {
a.attr.push([key, val])
}
return a
}, {
attr: [],
handlers: [],
bindedStyle: [],
bindedAttr: [],
bindedClasses: [],
show: null,
visible: true,
props: {},
parent: element.parentElement,
index: element.parentElement ? Array.prototype.indexOf.call(element.parentElement.children, element) : 0
})
}
export interface AttributesInterface {
attr: string[][],
handlers: string[][],
bindedStyle: string[][],
bindedAttr: string[][]
bindedClasses: string[][],
show: string,
visible: Boolean,
parent: HTMLElement,
index: number,
props: { [key: string]: string }
}
共享您的
tsconfig.json
.reduce((a: AttributesInterface, [key, val]) => {