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>
  • 相关阅读:
    android 项目
    input keyevent 数字对应的操作
    logcat 使用方法
    android查看内存使用情况
    图片点击放大效果
    禁止img图片拖动在新窗口打开
    人工智能
    游戏开发
    随手做的一个模拟弹出窗口
    Html的<meta>标签使用方法及用例
  • 原文地址:https://www.cnblogs.com/tian-sun/p/7405837.html
Copyright © 2011-2022 走看看