0

因此,当查询返回载波哈希的模型时,我在 Ember 中得到了 his.get('pic') "[object Object]" 。那么如何进入视图呢?

{"record":{"id":1234,"first_name":"John","gravepic":{"url":"http://c185643.r43.cf1.rackcdn.com/uploads/record/gravepic/13267/IMG_0013.JPG","ios":{"url":"http://c185643.r43.cf1.rackcdn.com/uploads/record/gravepic/13267/ios_IMG_0013.JPG"},"thumb":{"url":"http://c185643.r43.cf1.rackcdn.com/uploads/record/gravepic/13267/thumb_IMG_0013.JPG"},"small":{"url":"http://c185643.r43.cf1.rackcdn.com/uploads/record/gravepic/13267/small_IMG_0013.JPG"},"medium":{"url":"http://c185643.r43.cf1.rackcdn.com/uploads/record/gravepic/13267/medium_IMG_0013.JPG"},"large":{"url":"http://c185643.r43.cf1.rackcdn.com/uploads/record/gravepic/13267/large_IMG_0013.JPG"}},"eulogy":"FATHER","deceased":true,"gender":"male","photos":[{"accuracy":null,"approval":null,"asset_caption":"","asset_name":null,"assetpic":{"url":"http://c185643.r43.cf1.rackcdn.com/uploads/photo/assetpic/270/iccfa_350x200_3.jpg","thumb":{"url":"http://c185643.r43.cf1.rackcdn.com/uploads/photo/assetpic/270/thumb_iccfa_350x200_3.jpg"},"small":{"url":"http://c185643.r43.cf1.rackcdn.com/uploads/photo/assetpic/270/small_iccfa_350x200_3.jpg"},"medium":{"url":"http://c185643.r43.cf1.rackcdn.com/uploads/photo/assetpic/270/medium_iccfa_350x200_3.jpg"},"large":{"url":"http://c185643.r43.cf1.rackcdn.com/uploads/photo/assetpic/270/large_iccfa_350x200_3.jpg"}},"copyright":null,"coredata_id":null,"created_at":"2013-02-09T10:36:13Z","id":270,"ignore":null,"is_approved":true,"latitude":null,"longitude":null,"record_id":"13267","updated_at":"2013-02-09T10:36:13Z","user_id":1},{"accuracy":null,"approval":null,"asset_caption":null,"asset_name":null,"assetpic":{"url":null,"thumb":{"url":null},"small":{"url":null},"medium":{"url":null},"large":{"url":null}},"copyright":null,"coredata_id":null,"created_at":null,"id":null,"ignore":null,"is_approved":true,"latitude":null,"longitude":null,"record_id":13267,"updated_at":null,"user_id":null}],"copies":[{"content":null,"created_at":null,"id":null,"is_approved":true,"name":null,"record_id":13267,"summary":null,"updated_at":null,"user_id":null}],}}

接下来的问题将类似于record.photos.first.medium。或record.gravepic.small

只是不确定如何获得“对象对象”之外的东西

4

1 回答 1

2

我不确定这是否仍然是确切的 API,但如果你想从哈希中取出多个值,我建议添加一个新DS.attr类型。

DS.RESTAdapter.registerTransform('json', {
  deserialize: function(serialized) {
    return Em.isNone(serialized) ? {} : serialized;
  },
  serialize: function(deserialized) {
    return Em.isNone(deserialized) ? {} : deserialized;
  }
})

App.Something = DS.Model.extend({
  gravepic: DS.attr("json")
})
于 2013-02-12T08:45:59.283 回答