qor icon indicating copy to clipboard operation
qor copied to clipboard

action Modes属性中新添加的collection选项不可用

Open themoonstone opened this issue 7 years ago • 1 comments

实例如下:

` package main

import ( "fmt" "net/http" "github.com/qor/admin" "github.com/jinzhu/gorm" _ "github.com/jinzhu/gorm/dialects/mysql" "github.com/qor/qor" )

// Define a GORM-backend model type addAppMsg struct { gorm.Model Name string Sex string Date string

}

type Track struct { TrackName string Sex string }

func main() { // Set up the database conn := fmt.Sprintf("%s:%s@tcp(%s)/%s?charset=utf8&parseTime=true", "root", "123456", "localhost:3306", "qor_admin") DB, _ := gorm.Open("mysql", conn) DB.AutoMigrate(&addAppMsg{})

// Initalize
Admin := admin.New(&qor.Config{DB: DB})
user := Admin.AddResource(&addAppMsg{})
tk := Admin.NewResource(&Track{})
tk.Meta(&admin.Meta{
	Name:"Sex",
	Label:"性别",
	Config:&admin.SelectOneConfig{
		Collection:[]string{"M", "F"},
	},
})
Admin.AddMenu(&admin.Menu{Name: "user",  RelativePath: user.ToParam()})
user.Action(&admin.Action{
	Name:"Check",
	Handler: func(argument *admin.ActionArgument) error {

		return nil
	},
	Resource:tk,
	Modes: []string{"edit", "collection"},
})
user.Meta(&admin.Meta{
	Name:"Sex",
	Config:&admin.SelectOneConfig{
		Collection:[]string{"M", "F"},
	},
})

user.Meta(&admin.Meta{
	Name:"Name",
})

// Initalize an HTTP request multiplexer
mux := http.NewServeMux()

// Mount admin to the mux
Admin.MountTo("/admin", mux)

fmt.Println("Listening on: 9000")
http.ListenAndServe(":9000", mux)

} ` 在添加了collection之后、必须配置URL属性、否则引发panic : "Get error when render action 9.action.tmpl: reflect: call of reflect.Value.Interface on zero Value" , 但文档中未对该限制作出说明

themoonstone avatar Feb 09 '18 01:02 themoonstone

Type:       "select_one",
		Collection: []string{cms.QrcodeTypeCoffee},
Type: "select_one",
		Collection: func(value interface{}, context *qor.Context) [][]string {

owen-gxz avatar Jun 14 '18 06:06 owen-gxz