WeX5数据绑定:with绑定

优质
小牛编辑
136浏览
2023-12-01

with绑定用来创建一个绑定上下文,在子元素内的所有绑定都在这个上下文中进行。

示例代码:

//.W片段
<h1 bind-text="city"> </h1>
<p bind-with="coords">
 Latitude: <span bind-text="latitude"> </span>,
 Longitude: <span bind-text="longitude"> </span>
</p> 

//.js片段
city="London",
 coords= {
 latitude: 51.5001524,
 longitude: -0.1262362
 }

在上面的代码中,我们为段落p标签指定了数据上下文coords,在它的子元素中,我们就可以直接绑定coords的属性latitude和longitude了。

另外,with绑定也可以使用虚拟标签:

<ul>
    <li>Header element</li>
    <!-- justep.Bind with: outboundFlight -->
        ...
    <!-- /justep.Bind-->
    <!--justep.Bind with: inboundFlight -->
          ...
    <!-- /justep.Bind-->
 </ul>