Skip to content

table usage.md

cg33 edited this page Aug 5, 2018 · 1 revision

表格类型说明

配置展示表格,需要先知道展示表格的数据类型FieldStruct

type FieldStruct struct {
	ExcuFun  FieldValueFun
	Field    string
	TypeName string
	Head     string
}

其中Field代表字段名,TypeName代表字段类型名,Head代表表头名。 ExcuFun代表字段值过滤函数,定义如下:

type FieldValueFun func(value RowModel) interface{}

type RowModel struct {
	ID    int64
	Value string
}

传入的RowModel有两个属性,一个是ID,一个是Value。ID是该行数据记录的主键ID,Value代表该字段的值。

简单例子

// 列显示配置
userTable.Info.FieldList = []FieldStruct{
    {
        Head:     "姓名",
        Field:    "name",
        TypeName: "varchar",
        ExcuFun: func(model RowModel) string {
            return model.Value
        },
    },
    {
        Head:     "性别",
        Field:    "sex",
        TypeName: "tinyint",
        ExcuFun: func(model RowModel) string {
            if model.Value == "1" {
                return "男"
            }
            if model.Value == "2" {
                return "女"
            }
            return "未知"
        },
    },
}
Clone this wiki locally