Aurelia 如何在没有视图模型的情况下在自定义图元中创建多用途的可绑定对象?
我试图在没有视图模型的自定义元素中以两种稍有不同的方式使用单个可绑定元素 field-input.html:Aurelia 如何在没有视图模型的情况下在自定义图元中创建多用途的可绑定对象?,aurelia,Aurelia,我试图在没有视图模型的自定义元素中以两种稍有不同的方式使用单个可绑定元素 field-input.html: <template bindable="label,type,property"> <div class="form-group"> <label for="${property}">${label}</label> <input id="${property}" value.bind="${property}"
<template bindable="label,type,property">
<div class="form-group">
<label for="${property}">${label}</label>
<input id="${property}" value.bind="${property}" type="${type}">
</div>
</template>
我做错了什么?您必须使用
bind
而不是在引号内打印变量:
<template bindable="label,type,property,myValue">
<div class="form-group">
<label for.bind="property">${label}</label>
<input id.bind="property" placeholder.bind="property" value.bind="myValue" type.bind="type">
</div>
</template>
${label}
每次要绑定html属性时,只需调用attr.bind=“object”
,而不使用插值标记${}
从@Seth的解决方案更新
由于自定义元素中有一个输入元素,因此在组合视图中使用
myValue.two-way=“…”
非常重要。请参见您必须使用bind
而不是在引号内打印变量:
<template bindable="label,type,property,myValue">
<div class="form-group">
<label for.bind="property">${label}</label>
<input id.bind="property" placeholder.bind="property" value.bind="myValue" type.bind="type">
</div>
</template>
${label}
每次要绑定html属性时,只需调用attr.bind=“object”
,而不使用插值标记${}
从@Seth的解决方案更新
由于自定义元素中有一个输入元素,因此在组合视图中使用
myValue.two-way=“…”
非常重要。请参见当我这样做时,它绑定到属性的值,即“电子邮件”。这意味着输入的值始终是“email”,而不是viewmodel.email.bind将属性
对象绑定到占位符属性,如下所示placeholder.bind=“property”
。然后,创建另一个名为myValue
的可绑定属性,将其绑定到value对象。像这样value.bind=“myValue”
然后,在父对象中,将viewmodel.email
绑定到myValue
。看看我最新的答案,我怀疑这就是我必须要做的。如果您更新您的答案,我将接受它。由于我在自定义元素中有一个输入元素,因此在撰写视图中使用myValue.two-way=“…”
非常重要。看,当我这样做时,它绑定到属性的值,即“电子邮件”。这意味着输入的值始终是“email”,而不是viewmodel.email.bind将属性
对象绑定到占位符属性,如下所示placeholder.bind=“property”
。然后,创建另一个名为myValue
的可绑定属性,将其绑定到value对象。像这样value.bind=“myValue”
然后,在父对象中,将viewmodel.email
绑定到myValue
。看看我最新的答案,我怀疑这就是我必须要做的。如果您更新您的答案,我将接受它。由于我在自定义元素中有一个输入元素,因此在撰写视图中使用myValue.two-way=“…”
非常重要。看见
ERROR [app-router] TypeError: sourceExpression.connect is not a function(…)
<template bindable="label,type,property,myValue">
<div class="form-group">
<label for.bind="property">${label}</label>
<input id.bind="property" placeholder.bind="property" value.bind="myValue" type.bind="type">
</div>
</template>