douqie6454 2014-10-27 16:36
浏览 11
已采纳

通过Go获取Google的数据存储区密钥值

I have a struct:

type struct Foo {
    Id ??
    Name string
}

I get a list of Foos doing, where "c" is a NewContext():

    q := datastore.NewQuery("Drug")
    var foos []Foo
    _, err := q.GetAll(c, &foos)

The Id is not populated, but the Name is. I'm trying to figure out how to get the Id to populate

  • 写回答

1条回答 默认 最新

  • dragonpeng200811111 2014-10-27 16:49
    关注

    The GetAll function returns a slice of the keys:

    keys, err := q.GetAll(c, &foos)
    

    The key for foos[i] is keys[i].

    Use a loop to store the id in the entity if that's what you need:

    for i := range keys {
       foos[i].ID = keys[i].IntID() // or .StringID()
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 有人能看一下我宿舍管理系统的报修功能该怎么改啊?链表那里总是越界
  • ¥15 cs loadimage运行不了,easyx也下了,没有用
  • ¥15 r包runway详细安装教程
  • ¥15 Html中读取Json文件中数据并制作表格
  • ¥15 谁有RH342练习环境
  • ¥15 STM32F407 DMA中断问题
  • ¥15 uniapp连接阿里云无法发布消息和订阅
  • ¥25 麦当劳点餐系统代码纠错
  • ¥15 轮班监督委员会问题。
  • ¥20 关于变压器的具体案例分析