zoukankan      html  css  js  c++  java
  • 把分类的select写在moden里做成一个组件 高洛峰

    function selectform($name="pid", $pid=0) {
                $data = $this->field('id, concat(path, "-", id) as abspath, name')->order('abspath, id')->select();
                
                $html = '';
                
                $html .= '<select name="'.$name.'">';
    
                $html .= '<option value="0">--根分类--</option>';
                foreach($data as $row) {
                    //数量
                    $num = count(explode('-', $row['abspath']))-2;
                    //有一个数量 "-" 变成8个空格
                    $space =  str_repeat("|&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;", $num);
                    
                    $selected = ($pid == $row['id']) ? "selected" : '';
    
    
                    $html .='<option '.$selected.' value="'.$row['id'].'">'.$space.'|-'.$row['name'].'</option>';
                }
    
                $html .='</select>';
    
                return $html;
            }

    php:

    html调用输出:

  • 相关阅读:
    设计模式——策略模式
    LeetCode
    平凡世界里的万千思绪
    LeetCode
    LeetCode
    LeetCode
    LeetCode
    LeetCode
    LeetCode
    LeetCode
  • 原文地址:https://www.cnblogs.com/hnbiao/p/4949507.html
Copyright © 2011-2022 走看看