thinkphp 页面上循环checkbox选择的值和radio混用,if判断

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/hexiaoniao/article/details/68061902

页面效果:


每个数据表下有两个类型可以选择。一个是radio,一个是checkbox类型


数据:$views

array(2) {
  ["试听课数据表"] => array(4) {
    [1] => string(9) "未预约"
    [2] => string(9) "已预约"
    [3] => string(12) "试听结束"
    [4] => string(9) "未出席"
  }
  ["通话记录数据表"] => array(6) {
    [1] => string(9) "已接听"
    [2] => string(15) "振铃未接听"
    [3] => string(12) "排队放弃"
    [4] => string(9) "已留言"
    [5] => string(9) "IVR放弃"
    [6] => string(9) "黑名单"
  }

模板代码:

<foreach name="views" item="vo">
    <div class="control-group">
        <div class="span6">
            <div class="clearfix">
                <label class="control-label">{$key}</label>
                <div class="controls sex_3">
                    <div class="span3">
                        <label><input  class="radio" type="radio" name="{$key}" value="1"> 私有</label>
                    </div>
                    <div class="span3">
                        <label><input  class="radio" type="radio" name="{$key}" value="2"  > 按层级</label>
                    </div>
                    <div class="span3">
                        <label><input class="radio" type="radio" name="{$key}" value="3"  checked> 全部</label>
                    </div>
                </div>
            </div>
            <div class="clearfix">
                <label class="control-label">可浏览状态</label>
                <div class="controls sex_3">
                    <foreach name="vo" item="val" key="k">
                        <div class="span6" style="margin: 0">
                            <label><input  class="checkbox" type="checkbox" name="{$key}" value="{$k}">{$val}</label>
                        </div>
                    </foreach>
                </div>
            </div>
        </div>
    </div>
</foreach>

编辑的时候的数据:

$data_previlige

array(2) {
  [0] => array(7) {
    ["table_name"] => string(17) "audition_schedule"
    ["orid"] => string(2) "71"
    ["data_level"] => string(1) "2"
    ["create_date"] => string(10) "1490756124"
    ["last_modify_date"] => string(10) "1490756124"
    ["data_status"] => array(4) {
      [0] => string(1) "1"
      [1] => string(1) "2"
      [2] => string(1) "3"
      [3] => string(1) "4"
    }
    ["cn_table_name"] => NULL
  }
  [1] => array(7) {
    ["table_name"] => string(8) "call_log"
    ["orid"] => string(2) "71"
    ["data_level"] => string(1) "2"
    ["create_date"] => string(10) "1490756124"
    ["last_modify_date"] => string(10) "1490756124"
    ["data_status"] => array(6) {
      [0] => string(1) "1"
      [1] => string(1) "2"
      [2] => string(1) "3"
      [3] => string(1) "4"
      [4] => string(1) "5"
      [5] => string(1) "6"
    }
    ["cn_table_name"] => NULL
  }

编辑页面循环:

<foreach name="views" item="vo">
    <div class="control-group">
        <div class="span6">
            <div class="clearfix">
                <label class="control-label">{$vo['table_name']}</label>
                <div class="controls sex_3">
                    <div class="span3">
                        <label><input  class="radio" type="radio" name="{$vo['table_name']}" value="1" <if condition="$data_previlige[$key]['data_level'] eq 1">checked</if>> 私有</label>
                    </div>
                    <div class="span3">
                        <label><input  class="radio" type="radio" name="{$vo['table_name']}" value="2"  <if condition="$data_previlige[$key]['data_level'] eq 2">checked</if>> 按层级</label>
                    </div>
                    <div class="span3">
                        <label><input class="radio" type="radio" name="{$vo['table_name']}" value="3"  <if condition="$data_previlige[$key]['data_level'] eq 3">checked</if>> 全部</label>
                    </div>
                </div>
            </div>
            <div class="clearfix">
                <label class="control-label">可浏览状态</label>
                <div class="controls sex_3">
                    <foreach name="vo['data_status']" item="val" key="k">
                        <div class="span6" style="margin: 0">
                            <label><input  class="checkbox" type="checkbox" name="{$vo['table_name']}" value="{$k}" <if condition="in_array($k,$data_previlige[$key]['data_status'])">checked='checked'</if>>{$val}</label>
                        </div>
                    </foreach>
                </div>
            </div>
        </div>
    </div>
</foreach>


没有更多推荐了,返回首页