Ember 1.0.0 RESTAdapter失败 [英] Ember 1.0.0 RESTAdapter failure

查看:94
本文介绍了Ember 1.0.0 RESTAdapter失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我似乎无法追踪这个错误的来源:

I can't seem to track down the source of this error:


断言失败:没有找到'0'

Assertion failed: No model was found for '0'

JSON正在由服务器获取,但应用程序在发送到模板之前已经发生错误。 REST适配器和路由器之间似乎出现了问题。当我使用灯具适配器时,该模板会呈现无错误。

The JSON is getting fetched by the server, but the app is erroring out before it gets sent to the template. The problem seems to be happening between the REST adapter and the router. The template renders error-free when I use the fixture adapter.

我使用的是Ember和Handlebars版本1.0.0。

I'm using Ember and Handlebars versions 1.0.0.

这是我的应用程序代码:

Here's my App code:

window.App = Ember.Application.create();

App.ApplicationAdapter = DS.RESTAdapter.extend({
    host: 'http://localhost:3000'
});

App.Router.map(function() {
    this.resource("stories", { path: "/" }, function() {
        this.resource("boards", { path: "/boards"} )
    });
});

App.StoriesRoute = Ember.Route.extend({
    model: function() {
        return this.store.findAll('story');
    }
});

attr = DS.attr;

App.Story = DS.Model.extend({
    color: attr()
});

Handlebars模板

Handlebars templates

    <script type="text/x-handlebars">
    {{ outlet }}

    </script>

    <script type="text/x-handlebars" data-template-name="stories">
    <ul>
        <li class="storyLine">
            <ul>
                <li id="colorSwatch"></li>
                <li class="board">+</li>
            </ul>
        </li>
    </ul>
    <ul>
    {{#each model}}
        <li class="storyLine">
            <ul>
                <li id="colorSwatch" {{bindAttr class=story.color}}></li>
                <li class="board">dddd</li>
            </ul>
        </li>
    {{/each}}
    </ul>
    </script>

感谢您的帮助!

推荐答案

服务器的响应可能格式不正确。 JSON需要具有与您的模型相同名称的根。请参阅: http://emberjs.com/guides/models/the-rest-adapter/# toc_json-root
您的回复需要看起来像这样:

The response from the server probably isn't formatted correctly. The JSON needs to have a root that is the same name as your model. See: http://emberjs.com/guides/models/the-rest-adapter/#toc_json-root Your response needs to look something like this:

{
  "story": [
    {
      "id": 0,
      "title": "foo"
    },
    {
      "id": 1,
      "title": "bar"
    }
  ]
}

这篇关于Ember 1.0.0 RESTAdapter失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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