zoukankan      html  css  js  c++  java
  • template模板的使用方法

    模板


    WXML提供模板(template),可以在模板中定义代码片段,然后在不同的地方调用。
    定义模板

    使用name属性,作为模板的名字。然后在<template/>内定义代码片段
    使用模板

    使用is属性,声明需要的使用的模板,然后将模板所需要的data传入

    模板的作用域

    模板拥有自己的作用域,只能使用data传入的数据。
    example:
    定义模板 
    <template name="homecell">
         <view class="item">
                <image class="poster" src="{{item.images.small}}" />
                <view class="meta">
                    <text class="title">{{item.title}}</text>
                    <text class="sub-title">{{item.original_title}}({{item.year}})</text>
                    <view class="artists">
                        <text wx:for="{{item.directors}}">{{item.name}}</text>
                    </view>
                </view>
                <view class="rating">
                    <text>{{item.rating.average}}</text>
                </view>
        </view>
     </template>
    使用模板
    <import src="../../commonXml/homecell.wxml" />  //引入模板
    <loading hidden="{{!loading}}">加载中...</loading>
    <scroll-view scroll-y="true" class="page-body">
        <navigator wx:for="{{movies}}" url="../movie/movie?id={{item.id}}">
           <template is="homecell" data="{{item}}"></template>  //声明需要的使用的模板使用data传入的数据。
        </navigator>
    </scroll-view>
  • 相关阅读:
    numpy的shuffle函数
    特征值、特征向量
    keras的Embedding层
    自己写着玩的一个天气APP
    使用mbed进行STM32板子的开发
    提高ListView的效率
    自定义ListView里面的Item的内容
    Android控件使用自定义字体
    使用Handler类来更新UI
    MongoDB在Java下的增删查改
  • 原文地址:https://www.cnblogs.com/tian-sun/p/7405837.html
Copyright © 2011-2022 走看看