简体   繁体   English

如何使用 ng-repeat 访问动态数组并获取键值对

[英]How to access dynamic array and get key-value pairs using ng-repeat

I'm trying to retrieve data from json object for ionic mobile application.我正在尝试从离子移动应用程序的 json 对象中检索数据。 But the problem is inside that object has an array this array includes a set of objects.但问题在于该对象有一个数组,该数组包含一组对象。 I need to get the key and value pairs from those set of objects, I tried following code to achieve that.我需要从这些对象集中获取键和值对,我尝试了以下代码来实现这一点。

<ion-item ng-repeat="form in forms">
    <ion-item>
        {{form.Form_Group_Name}}
    </ion-item>
    <ion-item>
        <label class="item item-input item-stacked-label colone-input" ng-repeat="(key, value) in form.items">
            <span class="input-label">{{key}}</span>
            <input type="text" value="{{ value }}" placeholder="First name">
        </label>
    </ion-item>
</ion-item>

This is working, but as a key it shows the index of the array (see the following images).这是有效的,但作为一个键,它显示了数组的索引(见下图)。 Array size can be dynamically changed so then can't use index no to access this.数组大小可以动态更改,因此不能使用索引号来访问它。 I need to go inside the array and access the object to get key and value.我需要进入数组并访问对象以获取键和值。

here is the sample of my json object这是我的 json 对象的示例

在此处输入图片说明

result is like this :结果是这样的:

在此处输入图片说明

Thanks in advance.提前致谢。

This is how I did it:我是这样做的:

<ion-item ng-repeat="form in forms['Form Groups']">
    <ion-item >
        {{form['Form Group Name']}}
    </ion-item>
    <ion-item>
        <label class="item item-input item-stacked-label colone-input" ng-repeat="item in form.items">
            <div ng-repeat="(key, value) in item">
                <span class="input-label">{{key}}</span>
                <input type="text" value="{{ value }}" placeholder="value">
            </div>
        </label>
    </ion-item>
</ion-item>

As you can see here, I added <div> and inside that <div> iterate the item array.正如您在此处看到的,我添加了<div>并在该<div>迭代了 item 数组。 The item array includes all the data form json object and then I request key and value from array when the time of the iteration.项目数组包含所有数据形式的json对象,然后我在迭代时从数组中请求键和值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM