[TOC] >[warning] 函数依赖请查看本章第一节 [概述](http://www.kancloud.cn/donknap/we7/175036),使用前请务必 load()->func('tpl'); 加载模板组件函数 #### 组件 ##### 地区选择 >[info] tpl_app_form_field_district($name, $values = array()) * $name 表单字段的名称,同一页面不能为空 * $values 选中的地区信息,结构为 array('province' => '山西', 'city' => '太原', 'district' => '迎泽区') ``` <div class="mui-input-row"> <label>选择地区</label> {php echo tpl_app_form_field_district('address', array('province' => $address['province'],'city' => $address['city'],'district' => $address['district']));} </div> ``` ##### 日期选择 >[info] tpl_app_form_field_calendar($name, $values = array()) * $name 表单字段的名称,同一页面不能为空 * $values 选中的生日日期,结构为 array('year' => 2013,'month' => '10','day' => 3) ``` <div class="mui-input-row"> <label>出生日期</label> {php echo tpl_app_fans_form('birth', array('year' => $profile['birthyear'], 'month' => $profile['birthmonth'], 'day' => $profile['birthday']), $mcFields['birthyear']['title']);} </div> ``` >[warning] 下方说明一些比较简单的数据选择组件,由于使用简单,只提供示例 ##### 性别选择 ``` <div class="form-group"> <label class="col-xs-12 col-sm-3 col-md-2 control-label">性别</label> <div class="col-sm-9 col-xs-12"> {php echo tpl_fans_form('gender', $profile['gender']);} </div> </div> ``` ##### 血型选择 ``` <div class="form-group"> <label class="col-xs-12 col-sm-3 col-md-2 control-label">血型</label> <div class="col-sm-9 col-xs-12"> {php echo tpl_fans_form('bloodtype', $profile['bloodtype']);} </div> </div> ``` ##### 生肖选择 ``` <div class="form-group"> <label class="col-xs-12 col-sm-3 col-md-2 control-label">生肖</label> <div class="col-sm-9 col-xs-12"> {php echo tpl_fans_form('zodiac',$profile['zodiac']);} </div> </div> ``` ##### 星座选择 ``` <div class="form-group"> <label class="col-xs-12 col-sm-3 col-md-2 control-label">星座</label> <div class="col-sm-9 col-xs-12"> {php echo tpl_fans_form('constellation',$profile['constellation']);} </div> </div> ``` ##### 学历选择 ``` <div class="form-group"> <label class="col-xs-12 col-sm-3 col-md-2 control-label">学历</label> <div class="col-sm-9 col-xs-12"> {php echo tpl_fans_form('education',$profile['education']);} </div> </div> ``` ##### 自定义选择 自定义选项时只需要定义选择数据调用函数即可,数据可以在JS中定义,也可以在PHP中定义通过 json_encode 输出到模板中。 ``` <div class="mui-input-row"> <label>自定义选项</label> <input class="js-user-options" type="text" value="" readonly="" placeholder="请选择"> </div> <script type="text/javascript"> $(".js-user-options").on("tap", function(){ var options = {data: [ {"text":"测试1","value":"1"}, {"text":"测试2","value":"2"} ]}; var $this = $(this); util.poppicker(options, function(items){ $this.val(items[0].value); }); }); </script> ```