奥里利亚自定义元素 - $父未定义
我有模板,中继器:
其中打印结果:
0 - 0
0 - 1
1 - 0
1 - 1
如果我使用自定义元素child-item
用相同的模板:
<template>
<p>${ $parent.$index } - ${ $index }</p>
</template>
并使用child-item
写我的原始示例:
<template repeat.for="i of 2">
<child-item repeat.for="j of 2"></child-item>
</template>
结果只有:
-
-
-
-
有没有办法传播$家长和$指数透明的child-item
?
UPDATE
后尝试一些建议,最近我来到的是:
<template repeat.for="i of 2">
<child-item repeat.for="j of 2" parent-index.bind="$parent.$index" index.bind="$index"></child-item>
</template>
凡child-item
模板的样子:
<template bindable="parentIndex, index">
<p>${ parentIndex } - ${ index }</p>
</template>
绑定$parent
情况下直接与parent.bind="$parent"
不工作。父索引必须直接绑定。通过这种方法,任何与$parent.$parent.$index
内联的内容都无法实现。
您需要使用数据绑定才能将其传入。将或index
可绑定属性添加到child-item
视图模型。
这样的事会工作
儿童item.ts:你能
<template>
<require from="./child-item">
<child-item repeat.for="child of childred" index.bind="$index"></child-item>
</template>
'$ index'通过'bind(bindingContext:Object,overrideContext:Object)'中的'overrideContext'传递给自定义元素。所以'$ index'默认工作,不需要手动绑定。问题是如何使'$ parent'可用。 – Nenad
从代码中不清楚你需要'$ parent'作为什么? 'bindingContext'是父类,虽然 – classicalConditioning
我修改了问题,使其更加清晰,并添加更新后,我尝试了你和@ ashley授予建议。我也必须按照你的建议绑定索引。 – Nenad
:
儿童item.html
模板,中继器举个简单的例子? 'index.bind =“$ index”'似乎合乎逻辑,但当前绑定上下文的值应该是多少? 'parent.bind = “...”'? – Nenad