ember js从json获取元信息 [英] ember js get meta informations from json

查看:136
本文介绍了ember js从json获取元信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的服务器上有一个json数据:

  {
post:{
id:1,
title:Progressive Enhancement is Dead,
comments:[1,2],
links:{
user:/ people / tomdale
}
},

meta:{
total:100
}
}

看起来完全像文档( https://guides.emberjs.com/v2.5.0/models/handling-metadata/ )我试着获取不成功的元对象

 导出默认值Ember.Route.extend({
model(){
var data = this.store.findAll('post');
data.then((result)=> {
let meta = result.get('meta');
console.log(meta); // this return me undefined
})
return data;
}
});


解决方案

您正在使用findAll方法,它不支持元数据。如果要使用元数据获取多个帖子,则应该使用 this.store.query('post',{/ * params * /}) p>

i have a json data from my server:

{
  "post": {
    "id": 1,
    "title": "Progressive Enhancement is Dead",
    "comments": ["1", "2"],
    "links": {
      "user": "/people/tomdale"
    }
  },

  "meta": {
    "total": 100
  }
}

look exactly like the documentation (https://guides.emberjs.com/v2.5.0/models/handling-metadata/) i try to get the meta object with no success

export default Ember.Route.extend({
  model() {
    var data = this.store.findAll('post');
    data.then((result) => {
      let meta = result.get('meta');
      console.log(meta); //this return me undefined
    })
    return data;
  }
});

解决方案

You are using findAll method and it does not support meta data. You should use this.store.query('post', {/*params*/}) method instead, if you want to get multiple posts with meta data.

这篇关于ember js从json获取元信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆