Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/xpath/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Templates 来自http模拟的数据未显示在模板中_Templates_Ember.js_Ember Cli - Fatal编程技术网

Templates 来自http模拟的数据未显示在模板中

Templates 来自http模拟的数据未显示在模板中,templates,ember.js,ember-cli,Templates,Ember.js,Ember Cli,我在get http谓词上设置了一个http模拟,如下所示 usersRouter.get('/:pin', function(req, res) { res.json({ "users": { "id": 1234, "pin": 1234, "first_name": "John", "last_name": "Doe", "email": "ema

我在get http谓词上设置了一个http模拟,如下所示

usersRouter.get('/:pin', function(req, res) {
    res.json({
        "users": {
            "id": 1234,
            "pin": 1234,
            "first_name": "John",
            "last_name": "Doe",
            "email": "email@example.com",
            "phone": 8436376960
        }
    });
});
我的路线是通过从上一页的表单输入中以参数形式传递的pin码来查找此信息

model: function(params) {
    this.store.find('user', params.pin);
}
我的模板只是试图这样显示它们

<span class="name">{{first_name}} {{last_name}}</span>
<span class="email">{{email}}</span>
我没有在控制台中看到错误,但是页面上没有显示任何内容,在数据选项卡的ember inspector中,我看到我的数据正确地传递到路由

这里有我丢失的东西吗?这是我的第一个ember cli应用程序

更新:

根据Buck Doyle的回答,我对express代码进行了如下更新

usersRouter.get('/:pin', function(req, res) {
    var user = USERS.filter(function(el) {
      return el.pin == req.params.pin;
    });

    res.send({"users": [user]});
});
从外部定义的数组中提取。如下所示

var USERS = [
{
  "id": 1,
  "pin": 1234,
  "first_name": "John",
  "last_name": "Doe",
  "email": "email@example.com",
  "phone": 8436376960
},
{
  "id": 2,
  "pin": 5678,
  "first_name": "Jane",
  "last_name": "Smith",
  "email": "email@example.org",
  "phone": 8436375738
}
];
我现在得到一个断言错误

Uncaught Error: Assertion Failed: Error: Assertion Failed: Expected an object as `data` in a call to `push`/`update` for user , but was [object Object]

余烬检查器不再显示返回的数据。

用户应返回数组,而不是对象:

"users": [{
  "id": 1234,
  "pin": 1234,
  "first_name": "John",
  "last_name": "Doe",
  "email": "email@example.com",
  "phone": 8436376960
}]
但如果正确,则需要在
usersRouter
中进行筛选。如果将上述内容另存为用户:

usersRouter.get('/:pin', function(req, res) {
  var pin = req.params.pin;
  var user = USERS.filter(function(user) {
    return user.pin.toString() == pin;
  })[0];
  res.send({"users": user});
});
我可以通过运行您的测试应用程序并直接访问存储来验证上述内容,因为我不理解您的接口应该如何工作

store = WmiCheckIn.__container__.lookup('store:main');
jane = store.find('user', '5678')
console.log(jane.get('first_name')); // -> Jane

这里肯定发生了别的事情,我仍然在犯这些错误。我在github上发布了我的工作代码以供参考。我尝试过应用你的更新,但没有成功。我能够摆脱断言错误,运行控制台命令并获得相同的输出,但内容仍然无法显示在模板中。我注意到我没有退回store.find,在store.find之前添加了return。find最终将其放入我的模板中。谢谢你的帮助!
store = WmiCheckIn.__container__.lookup('store:main');
jane = store.find('user', '5678')
console.log(jane.get('first_name')); // -> Jane