1 回答
TA贡献2080条经验 获得超4个赞
经过一定量的实验后,发现这里是如何Save()为具有结构的对象实现方法。datastore.Property 必须存储持有数组[]interface{}而[]*datastore.Entity不是纯数组[]*datastore.Entity:
func (p *Person) Save() ([]datastore.Property, error) {
props := []datastore.Property{
{
Name: "Name",
Value: p.Name,
},
}
var n []interface{}
for _, x := range p.Phone {
i1 := datastore.Property{Name: "Type", Value: x.Type}
i2 := datastore.Property{Name: "Number", Value: x.Number}
e := &datastore.Entity{Properties: []datastore.Property{i1, i2}}
n = append(n, e)
}
props = append(props, datastore.Property{Name:"Phone",Value:n})
return props, nil
}
- 1 回答
- 0 关注
- 94 浏览
添加回答
举报