• 关于“类型”字段的处理


    很多时候我们会遇到一个东西输入某个类型的情况

    比如一个产品的分类,这里的type字段:

    1

    通常我们会用0 1 2来表示不同的类型,而不是具体的文字(如手机、电脑、鼠标这样的文字),这就导致了一个问题,前端显示内容

    最原始的方法是这样:

    <select name="type">
    <option value="0" <if condition="$rs['type'] eq 0">selected="true"</if>>广告</option>
    <option value="1" <if condition="$rs['type'] eq 1">selected="true"</if>>建材</option>
    <option value="2" <if condition="$rs['type'] eq 2">selected="true"</if>>素材</option>
    </select>
    

    而现在有了更方便的方法,使用一个数据表来保存type的数字类型和文字类型的对应关系:

    2

    有了这个表之后就方便多了,只需在后台取出这个表的数据分配到前端,前端进行遍历即可

    后台:

    $m=M('type');
    $rs=$m->select();
    $this->assign('type',$rs);
    

    前端:

    <select name="type">
    <foreach name='type' item='val'>
    <option value="<{$val['type_id']}>" <if condition="$rs['type'] eq $val['type_id']">selected="true"</if>><{$val['type_name']}></option>
    </foreach>
    </select>
    
  • 相关阅读:
    ipv6 for openwrt odhcpd
    openwrt package Makefile
    openwrt 中个网络接口协议说明[转]
    openwrt Package aircrack-ng is missing dependencies for the following libraries:
    linux kernel 从cmdline 提取值
    js 上传文件进度条 [uboot使用]
    printk打印级别 [转]
    linux c 宏定义
    uboot 开发记录
    mac ssh scp命令
  • 原文地址:https://www.cnblogs.com/3body/p/5416727.html
Copyright © 2020-2023  润新知