如何在angularjs中使用json在单个tr中打印两个不同的数组元素

时间:2018-07-20 05:42:05

标签: angularjs json

我想在一个tr中打印两个数组。我的json就像

[{"group_name":"Ecofresh","id":"19","userId":"19","device_details":[{"userid":"19","unit_id":"35","unit_name":"Test123","mac_id":"EB9F5E5727D7","m2xa":"95005c74d3cb33ca320e4b92cdee617d","m2xd":"5a00144b70bda43667498cf44677ad3e","mdlno":"Mtemp","group_id":"19","watchstat":"0","battery":"3.02","network":"-58","updatetime":"2018-06-22 11:50:20 ","unitShow":[{"unit":"celcius"},{"unit":"%"}],"channels":[{"id":"106865","chkey":"ch1","chvalue":"30","updatetime":"2018-06-22 11:50:20 ","unit_id":"35"},{"id":"106866","chkey":"ch2","chvalue":"69","updatetime":"2018-06-22 11:50:20 ","unit_id":"35"}]},{"userid":"19","unit_id":"46","unit_name":"T4","mac_id":"E51068E8A28C","m2xa":"f6852dfc4b49908c02a3d7893eba6331","m2xd":"4c798928f651626ccb2a30ffbd4820c3","mdlno":"Mtemp","group_id":"19","watchstat":"0","battery":"3.04","network":"-62","updatetime":"2018-06-22 11:50:21 ","unitShow":[{"unit":"celcius"},{"unit":"celcius"}],"channels":[{"id":"106867","chkey":"ch1","chvalue":"30","updatetime":"2018-06-22 11:50:21 ","unit_id":"46"},{"id":"106868","chkey":"ch2","chvalue":"69","updatetime":"2018-06-22 11:50:21 ","unit_id":"46"}]},{"userid":"19","unit_id":"47","unit_name":"T2","mac_id":"C0A02FF440A1","m2xa":"ed2e2b818fbe24584c6a7b50b3db8d9e","m2xd":"4e2f9beb516da0a65361770fd2276c0d","mdlno":"Mtemp","group_id":"19","watchstat":"0","battery":"3","network":"-62","updatetime":"2018-06-22 11:50:24 ","unitShow":[{"unit":"%"},{"unit":"%"}],"channels":[{"id":"106869","chkey":"ch1","chvalue":"30","updatetime":"2018-06-22 11:50:24 ","unit_id":"47"},{"id":"106870","chkey":"ch2","chvalue":"68","updatetime":"2018-06-22 11:50:24 ","unit_id":"47"}]}]}]

和代码是。

<tr  ng-repeat="item3 in item1.channels"  ng-show="item3.chkey !=null "&&"item3.value!= null"><td> {{item3.chkey}}={{item3.chvalue}}</td> </tr>

想要在chvalue旁边显示元素 unitShow 。表示我要打印的第一行

ch1 = 30摄氏度
ch2 = 69%

像这样

1 个答案:

答案 0 :(得分:1)

您可以使用$ index访问第一个数组中的元素。

    func uplaodImages(_ url: String,parameters: Dictionary<String,AnyObject>?,imageDataArray:[UIImage], compBlock : @escaping completionBlock,failure : @escaping failureBlock)
{

    let headers: HTTPHeaders = [
        /* "Authorization": "your_access_token",  in case you need authorization header */
        "Content-type": "multipart/form-data"
    ]
    Alamofire.upload(multipartFormData: { multipartFormData in

        for (key, value) in parameters! {
            if let data = value.data(using: String.Encoding.utf8.rawValue) {
                multipartFormData.append(data, withName: key)

            }
        }

        for i in 0..<imageDataArray.count{
            let imageData1 = UIImageJPEGRepresentation(imageDataArray[i], 1.0)!
            multipartFormData.append(imageData1, withName: "morephoto[\(i)]" , fileName: "photo" + String(i) + ".jpg", mimeType: "image/jpeg")
        }

    },
                     to: url,method:HTTPMethod.post,
                     headers:headers, encodingCompletion: { encodingResult in
                        switch encodingResult {
                        case .success(let upload, _, _):
                            upload
                                .validate()
                                .responseJSON { response in
                                    switch response.result {
                                    case .success(let value):
                                        compBlock(value as AnyObject,true)
                                        print("responseObject: \(value)")
                                    case .failure(let responseError):
                                        print("responseError: \(responseError)")
                                    }
                            }
                        case .failure(let encodingError):
                            print("encodingError: \(encodingError)")
                            let errorDesc = (encodingError as NSError).localizedDescription
                            failure(errorDesc as NSString,false)
                        }
    })


}