不太明白,微信小程序中组件间关系relations的作用。文档中实例是这样的:
<custom-ul>
<custom-li> item 1 </custom-li>
<custom-li> item 2 </custom-li>
</custom-ul>
// path/to/custom-ul.js
Component({
relations: {
'./custom-li': {
type: 'child' // 关联的目标节点应为子节点
}
},
methods: {
_getAllLi: function(){
// 使用getRelationNodes可以获得nodes数组,包含所有已关联的custom-li,且是有序的
var nodes = this.getRelationNodes('path/to/custom-li')
}
},
ready: function(){
this._getAllLi()
}
})
// path/to/custom-li.js
Component({
relations: {
'./custom-ul': {
type: 'parent' // 关联的目标节点应为父节点
}
}
})
以下是我的问题:
实例中组件的结构已经表明了嵌套关系
<custom-ul>
<custom-li> item 1 </custom-li>
<custom-li> item 2 </custom-li>
</custom-ul>
那么请问relations这个自定义字段,代表什么意思呢?有什么具体用途实例?