Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/jpa/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Aurelia 如何在没有视图模型的情况下在自定义图元中创建多用途的可绑定对象?_Aurelia - Fatal编程技术网

Aurelia 如何在没有视图模型的情况下在自定义图元中创建多用途的可绑定对象?

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}"

我试图在没有视图模型的自定义元素中以两种稍有不同的方式使用单个可绑定元素

field-input.html:

<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>