-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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 "未知"
},
},
}