English 中文(简体)
EmberJS - 在对象内从内层矩阵中创建/获取对象并采取行动
原标题:EmberJS - Creating/Accessing Objects from Nested Array within an Object and Acting on it
  • 时间:2012-05-23 21:27:48
  •  标签:
  • ember.js

从服务器上返回的我的 JSON 对象看起来像这个 :

[
  { 
    "id" : 1, 
    "name": "Biking", 
    "type": [{ 
      "id" : 1, 
      "name" : "Road"
    }]
  },
  { 
    "id" : 2, 
    "name": "MotorCycling",
    "type": [{ 
      "id" : 1, 
      "name" : "MX", 
      "alias" : { 
        "name": "Dirt", 
        "showaliasonsportid": [1,2,3] 
        } 
    }
  ]}
]

我的JJ看起来像这个

App.Activity = Em.Object.extend({
});

App.ActivityListView = Em.View.extend({ 
});

App.activitiesController = Em.ArrayProxy.create({ 
    content: [],

    loadActivities: function () {
      var self = this;
      $.getJSON( data/activities.json , function(data) {
        data.forEach(function(item) {
          self.pushObject(App.Activity.create(item));
        });
      });
    }
});

我的问题是,我如何在 showaliassonsportid 阵列上行动, 甚至如何访问它来显示别名. name, 而不是类型. name value? 我读过, 我可能需要从别名和或 showaliassonsportid 阵列中创建一个对象, 但我对如何用 Ember 来做到这一点感到困惑 。

最佳回答

检查Ember Data, 它能很好地解决这类问题 : < a href="https://github.com/emberjs/data" rel="no follow" >https://github.com/emberjs/data

问题回答

暂无回答




相关问题
Are Recursive Collections possible in sproutcore2?

I have a customizable navigation tree that can be nested 3 levels deep. Templates: <script type="text/x-handlebars" data-template-name="NavItemView"> <a {{bindAttr href="href" class="...

ember.js widgets

I know that ember js is good for single page apps and it appears that you can localize ember js app to a single dom container rather than the whole page, so I m wondering if ember js would be a good ...

Ember.js binding models stored within an array

What is the correct way to bind from one model to another when the models are stored within an array? Typically I d imagine that this would be a Controller s content array, but to keep the example ...

rendering views dynamically on EmberJS

I just having a little trouble to implement a special kind of view for Ember, I m digging on the source for days but can t find how to make it work... Can you take a look and tell me what s wrong? It ...

热门标签