如何使用角度js检索数据,并在MYSQL coloumn中存储json格式

时间:2017-12-05 06:39:10

标签: mysql angularjs json

我有像这样存储在MySQL列中的JSON数据,列名是payments_json_details

[{"amount":"1000","mop":"Cash","paymentdate":"2017-12-04 16:25","remarks":"testt1"},{"amount":"2500","mop":"Cheque","paymentdate":"2017-12-05","remarks":"testt2"}] 

当我们使用这个角度js用于显示目的时,我可以获得上面的数据,但我想检索每个值,如金额,拖把等

{{pdata.deliveryinfo[index].payments_json_details}}

<span ng-repeat="(key, value) in pdata.deliveryinfo[index].payments_json_details">
        {{value}}
</span>

我试过这种方式,但是没有输出,有人可以帮忙吗?

JSON format like this

    {
        "jobcard_id": "33",
        "jobcard_sno": "8",
        "user_id": "140",
        "address_id": "22",
        "delivery_address_id": "22",
        "orderdetails": [{
            "id": "71",
            "jobcard_id": "33",
            "product_id": "462",
            "product_quantity": "2",
            "product_price": "324.00"
        }],
        "deliverydetails": [{
            "id": "4",
            "type": "Delivery Agent"
        }, {
            "id": "5",
            "type": "Delivery Agent"
        }],
        "deliveryinfo": [{
            "delivery_id": "7",
            "order_id": "33",
            "product_ids": "462",
            "payment_collected": "Partial",
            "payments_json_details": "[{\"amount\":\"1000\",\"mop\":\"Cash\",\"paymentdate\":\"2017-12-04 16:25\",\"remarks\":\"testt1\"},{\"amount\":\"2500\",\"mop\":\"Cheque\",\"paymentdate\":\"2017-12-05\",\"remarks\":\"testt2\"}]",
            "totaltime": "39:17:00"
        },{
            "delivery_id": "7",
            "order_id": "35",
            "product_ids": "485",
            "payment_collected": "Partial",
            "payments_json_details": "[{\"amount\":\"5000\",\"mop\":\"Cash\",\"paymentdate\":\"2017-12-04 16:25\",\"remarks\":\"testt1\"},{\"amount\":\"7000\",\"mop\":\"Cheque\",\"paymentdate\":\"2017-12-05\",\"remarks\":\"testt2\"}]",
            "totaltime": "39:17:00"
}],
        "$$hashKey": "testt"
    }

1 个答案:

答案 0 :(得分:0)

我在考虑pdata.deliveryinfo是一个包含JSON对象的数组。如果是pdata.deliveryinfo[index].payments_json_details,请在ng-repeat中使用它。

<span ng-repeat="data in pdata.deliveryinfo>
   Amount: {{data.amount}}, MOP : {{data.mop}}, Payment Date : {{data.paymentdate}}, Remarks : {{data.remarks}}
</span>