我正在学习Ember JS和Handlebars JS,所以我对此非常陌生。我试图循环使用以下JSON时遇到问题。
这是我的JSON:
{
"sgt_rules": {
"app_tags": {},
"city": [],
"consumer_tags": [],
"device_tags": {
"os": [
"ios"
]
},
"participation": null,
"registration": null
}
}
这是我的车把模板:
<h2>{{controllers.segment.sgt_name}}</h2>
<script type="text/x-handlebars" data-template-name="pull">
<ul>
<li>{{getsegmentrules}}</li>
</ul>
</script>
我需要修改它时的ember辅助函数:
import Ember from 'ember';
var controller = Ember.Controller.extend({
needs: ['segment'],
getsegmentrules: function () {
var model = this.get('content').get('sgt_rules');
}.property()});
export default controller;
我试过这个,但它不起作用:
<script type="text/x-handlebars" data-template-name="pull">
<ul>
<li>{{controllers.segment.sgt_rules}}</li>
{{#each segment in controllers.segment.sgt_rules}}
<li>App Tags: {{segment.app_tags}} <br /> City: {{segment.city}} <br />
Consumer Tags: {{segment.consumer_tags}} <br /> Device Tags: {{segment.device_tags}} <br />
Participation: {{segment.participation}} <br /> Registration: {{segment.registration}} <br />
<ul>
{{#each obj in segment.device_tags}}
<li>{{obj.os}}</li>
{{/each}}
</ul>
</li>
{{/each}}
</ul>
</script>
我在这里缺少什么?我是否还需要编写任何辅助函数?
答案 0 :(得分:0)
你不应该在这里返回一个值吗?
getsegmentrules: function () {
var model = this.get('content').get('sgt_rules');
return model;
}.property()});
您还在哪里设置JSON数据?