-
Notifications
You must be signed in to change notification settings - Fork 34
/
single_value_list.go
54 lines (45 loc) · 1.12 KB
/
single_value_list.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package forms
import (
stringutil "github.com/iwind/TeaGo/utils/string"
"net/http"
)
// 单值列表
type SingleValueList struct {
Element `yaml:",inline"`
ValueName string `yaml:"valueName" json:"valueName"`
}
// 获取新对象
func NewSingleValueList(title string, subtitle string) *SingleValueList {
return &SingleValueList{
Element: Element{
Title: title,
Subtitle: subtitle,
},
}
}
// 获取父级类型
func (this *SingleValueList) Super() *Element {
return &this.Element
}
// 组合
func (this *SingleValueList) Compose() string {
model := this.Namespace + "_" + this.Code + "_single_values"
this.Javascript = `
this.` + model + ` = ` + stringutil.JSONEncode(this.Value) + `;`
attrs := this.ComposeAttrs(map[string]string{
"value-name": this.ValueName,
"prefix": this.Code,
":values": model,
})
return `<single-value-list ` + attrs + `></single-value-list>`
}
// 获取值
func (this *SingleValueList) ApplyRequest(req *http.Request) (value interface{}, skip bool, err error) {
values, ok := req.Form[this.Code+"Values"]
if !ok {
value = []string{}
return
}
value = values
return
}