本文介绍了Ember Handlebars迭代对象和显示键嵌入每个帮助器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的Ember Handlebars模板中迭代和渲染一些文本



我有一个如下的JSON: (在项目内)

 reas:{显示文本1:[null],显示文本2 [null]} 

我想在UI上显示文本(显示文本1 /显示文本2)即我对象的键。所以在我的Ember Handlebars模板中,我做

  {{#item.reas中的每个项目}} 
< TR>
< td> {{item}}< / td>
< / tr>
{{/ each}}

此前我还尝试过{{@key}



但是我无法获取文字。我做错了什么?



PS:请记住,这是Ember中的Handlebars,这是嵌套的,即每个都有一个

解决方案

给定以下JSON(从您的问题的美化版本):

  {
reason:{
显示文本1:[
null
],
显示文本2:[
null
]
}
}

您可以使用帮助者:

  {{ #each-in item.reasons as | key value |}} 
< tr>
< td> {{key}}< / td>
< / tr>
{{/ each-in}}


I want to iterate and render some text in my Ember Handlebars template

I have a JSON as below; (comes within item)

"reas":{"Display Text 1":[null],"Display Text 2":[null]}

I want to display the text (Display Text 1/Display Text 2) on UI i.e. keys of my object. So in my Ember Handlebars template, I do

{{#each item in item.reas}}
    <tr>
        <td>{{item}}</td>
    </tr>
{{/each}}

Earlier I had also tried the {{@key}

But I am unable to get the text. What am I doing wrong ?

PS: Please remember that this is Handlebars within Ember and this is nested each i.e. there is an outer each in the template.

解决方案

Given following JSON (beautified version of one from your question):

{
    "reasons": {
        "Display Text 1": [
            null
        ],
        "Display Text 2": [
            null
        ]
    }
}

You could iterate on it using {{each-in}} helper:

{{#each-in item.reasons as |key value|}}
    <tr>
        <td>{{key}}</td>
    </tr>
{{/each-in}}

这篇关于Ember Handlebars迭代对象和显示键嵌入每个帮助器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-02 13:34