后台:
1、model的list方法中,查询方法后加RelatedSel(),把关联对象装载出来
query := orm.NewOrm().QueryTable(AccompanyPersonTBName()).RelatedSel()
2、Controller的edit方法中:
关联对象需要单独加载
m := models.AccompanyPerson{}
person := &models.Hisperson{}
personId, _ := c.GetInt("Person", 0)
if personId > 0 {
person, err = models.HispersonOne(personId)
if err == nil && person != nil {
m.Person = person
} else {
c.jsonResult(enums.JRCodeFailed, "陪护患者无效", "")
}
}
结构体
type AccompanyPerson struct {
Id int
CreateTime string
Person *Hisperson `orm:"null;rel(fk)"` // RelForeignKey relation
}
ui:
列表:
},{
field: 'Person.Czyh',
title: '住院号'
},{
field: 'Person.Czycw',
title: '床位号' ,
sortable: true,
},{
field: 'Person.Cxm',
title: '患者姓名'
},{
编辑:
<div class="form-group">
<label class="col-sm-2 control-label">陪护患者</label>
<div class="col-sm-8">
<select name="Person" id="Person" class="form-control">
</select>
</div>
</div>
验证:
$thisForm.sdvalidate({
rules: {
Person: {
required: true
},
TestType: {
required: true
},
TestState: {