2

FIXTURESember-model を使用して作成しましたが、テンプレートで次のノードを使用できません

    "logged_in": {
        "id" : "1",
        "logged": true,
        "username": "sac1245",
        "account_id": "4214"
    } 

このノードのリレーションを実装belongsToしましたが、1 つのエラーがスローされます:Uncaught Error: Ember.Adapter must implement findQuery
ここにモデル コードをリストしました:

Astcart.Application =  Ember.Model.extend({
    name: Ember.attr(),
    logo_url : Ember.attr(),
    list: Ember.hasMany('Astcart.List', {key: 'list', embedded: true}),
    logged_in: Ember.belongsTo('Astcart.Logged_in', {key: 'logged_in'})
});

    Astcart.List = Ember.Model.extend({
      name: Ember.attr()
    });

    Astcart.Logged_in = Ember.Model.extend({
      id: Ember.attr(),
      logged: Ember.attr(),
      username: Ember.attr(),
      account_id: Ember.attr()
    });

    Astcart.Application.adapter = Ember.FixtureAdapter.create();

    Astcart.Application.FIXTURES = [
        {
            "id"     : "1",
            "logo_url": "img/logo.jpg",
            "logged_in": {
                "id" : "1",
                "logged": true,
                "username": "sac1245",
                "account_id": "4214"
            },          
            "name": "gau",
            "list": [
                        {
                            "id"     : "1",
                            "name": "amit"
                        },
                        {
                            "id"     : "2",                 
                            "name": "amit1"
                        }
            ]
        }
    ];

テンプレートコード:

    {{#each item in model}}
        {{item.name}}
        {{item.logged_in.logged}}                               
    {{/each}}

ルーターコード:

  Astcart.ApplicationRoute = Ember.Route.extend({
    model: function() {
      return Astcart.Application.find();
    }
  }); 

テンプレートで上記のノードのデータにアクセスする方法を教えてもらえますか?

4

1 に答える 1

3

現在のフィクスチャにはlogged_inデータが埋め込まれています。

Astcart.Application.FIXTURES=[
    {
        ...
        "logged_in": {
            "id": "1",
            "logged": true,
            "username": "sac1245",
            "account_id": "4214"
        },
        ...
    }
];

したがって、プロパティ マッピングには、次のように、このデータを検索できるようにlogged_inパラメータが必要です。embedded: true

Astcart.Application =  Ember.Model.extend({
  ...
  logged_in: Ember.belongsTo('Astcart.Logged_in', {key: 'logged_in', embedded: true })
});

これがないと、次のクエリを試行しますAstcart.Logged_in

Astcart.Logged_in.find(1)

アダプターがないため、次の例外で失敗します。Uncaught Error: Ember.Adapter must implement findQuery

これがそのフィドルで機能しているのを見ることができますhttp://jsfiddle.net/marciojunior/8zjsh/

于 2013-09-02T14:01:59.467 に答える