【发布时间】:2015-05-05 19:16:59
【问题描述】:
我有一个组件可以像这样从我的控制器中获取一些当前的夹具数据
{{vertical-graph metrics=controller.total_sessions_comparison}}
控制器属性如下所示
total_sessions_comparison: [
[
{
metricNumber: "26%",
metricText: "September",
metricStyle: "height: 26%"
},
{
metricNumber: "22%",
metricText: "October",
metricStyle: "height: 22%"
},
],
[
{
metricNumber: "74%",
metricText: "September",
metricStyle: "height: 74%"
},
{
metricNumber: "78%",
metricText: "October",
metricStyle: "height: 78%"
}
]
],
我的路由器中的模型挂钩正在从这样的自定义 express api 加载数据
return Ember.$.getJSON('http://127.0.0.1:3000/api');
目前我的 API 正在返回如下所示的 JSON
{
"total_sessions": 288,
"current_month": "May",
"current_month_year": "2015",
"last_month": "December",
"last_month_year": "2014"
}
我可以很好地访问模板中的模型数据(这些都在索引下)但是我在理解如何在控制器属性中获取月份名称而不是硬编码它们时遇到了一些问题通过 API 动态传递。模型属性看起来像 current_month 和 last_month,就像我说的在模板中工作,但我无法让它们在控制器中工作。
或者有没有比我目前更好的方法可以让这更容易?
【问题讨论】:
-
你的问题对我来说没有多大意义。你只是随机开始谈论几个月,但控制器属性是关于指标的,我在任何地方都看不到
current_month或last_month。告诉我你的路线代码 -
用我的 JSON API 的当前响应更新了它,路由代码也是 Ember.$.getJSON(...) 位,它在索引路由的模型钩子中。
-
这是一个开始。现在“让它们在控制器中工作”是什么意思
-
所以在控制器属性中我有月份作为字符串,但我想使用从 JSON API 传递的那些而不是写出来。这有意义吗?
标签: json ember.js model controller