访问元回复消息

时间:2013-11-16 12:26:21

标签: ember.js ember-data

我的支持是在meta字段中向我提供有关回复的一些信息。例如,当转到#/phoneNumbers/phonelocations/index时,会向/api/phonelocations发送请求,这是收到的数据:

{
    "meta": {
        "api_action": "find_all",
        "api_id": "phonelocations",
        "content_type": "application/json",
        "error_code": 200,
        "errors": [
            {
                "admin_message": "",
                "code": 200,
                "message": ""
            }
        ],
        "message": "Successfully read phonelocations",
        "success": true
    },
    "phonelocations": [
        {
            "_id": "0",
            "city": "Berlin",
            "count": 10,
            "country": "DE",
            "country_name": "Germany",
            "loctype": "GEO",
            "loctype_human": "Geographical number",
            "subtype": "49GEO",
            "subtype_human": "German geographical number",
            "type": "phonelocation-faketype"
        },
        ...
    ]
}

这存在于来自后端的所有回复中。我想使用_reply_meta.message中的消息将其显示给用户。 Ember中是否有标准方法来访问回复的元信息?

1 个答案:

答案 0 :(得分:1)

在您的情况下,只需使用store.metadataFor(type)

var meta = this.store.metadataFor('phonelocation');
// all metadata is in meta object
meta.message // => "Successfully read phonelocations"

在行动http://jsfiddle.net/marciojunior/3vfQD/

中查看此内容