具有多行字符串的AngularJS和JSON

时间:2021-04-13 18:14:57

I have organised my data in JSON file, which contains multi-line string, separated in the array. Like this:

我已将数据组织在JSON文件中,该文件包含多行字符串,在数组中分隔。喜欢这个:

[
    {
        "name": "1. Some Name",
        "id": "1",
        "description": [
            "Some long text 1 ",
            "Some long text 2 "
       ]
    },
    {
        "name": "2. Some Name",
        "id": "2",
        "description": [
            "Some long text 1 ",
            "Some long text 2 "
        ]
    }
]

Then in my view I want show text in description:

然后在我看来我想在描述中显示文字:

<ion-view view-title="">
<ion-content>
    <div class="card">
        <div class="item item-text-wrap" 
             ng-repeat="rule in rules | filter: { id: whichid }">
            {{ rule.description }}
        </div>
    </div>
</ion-content>

And my output look like this:

我的输出看起来像这样:

["Some long text 1","Some long text 2"]

How I can remove (or filter) that character '[' , '"' and ','?

我如何删除(或过滤)该字符'[','''和','?

Or if i use ng-bind-html="rule.description" directive i got:

或者,如果我使用ng-bind-html =“rule.description”指令,我得到:

Some long text 1 ,Some long text 2

Basically that is fine output, but they contain a comma ',' (which is in the array).

基本上这是很好的输出,但它们包含一个逗号','(在数组中)。

2 个解决方案

#1


0  

You can also try Array.join() method.

您也可以尝试使用Array.join()方法。

Link: Array.join()

In your case: {{ rule.description.join(' ') }}

就你而言:{{rule.description.join('')}}

#2


1  

try like this

试试这样

 <div class="item item-text-wrap" 
         ng-repeat="rule in rules | filter: { id: whichid }">
        <span ng-repeat="d in rule.description">{{ d }}</span>
    </div>

#1


0  

You can also try Array.join() method.

您也可以尝试使用Array.join()方法。

Link: Array.join()

In your case: {{ rule.description.join(' ') }}

就你而言:{{rule.description.join('')}}

#2


1  

try like this

试试这样

 <div class="item item-text-wrap" 
         ng-repeat="rule in rules | filter: { id: whichid }">
        <span ng-repeat="d in rule.description">{{ d }}</span>
    </div>