javascript - Mengapa traversal dua lapisan tidak boleh dilaksanakan dalam pengawal dalam sudut?
仅有的幸福
仅有的幸福 2017-07-05 10:55:57
0
1
810

Saya perlu melaksanakan fungsi ini, melintasi data yang diperoleh ke satu tahap, dan kemudian melintasi setiap item, dan menetapkan nilai tertentu bagi setiap data item ke lapisan sebelumnya, tetapi ia tidak boleh dilaksanakan. Apa nak buat?
Kod: var datalist=[];

                var dataDe = data.body.data.assets;
                for(var i = 0;i<dataDe.length;i++){
                    for(var j= 0;j<dataDe[i].userAssetList.length;j++){
                        dataDe[i].userDtoName = dataDe[i].userAssetList[j];
                        datalist.push(dataDe[i]);
                    }
                }
                $scope.datalist=datalist;
              事实证明第二个循环里面的值alert可以出来。但是赋值给外层的元素就不行了。怎么解决。求大神。
              数据结构如下:我是想把userassetlist里面的数组进行遍历然后赋值给上一层。
                                "data": {
        "assets": [
            {
                "id": "001",
                "assetCount": 14,
                "availableCount": 9,
                "price": 2,
                "startDate": null,
                "age": 0,
                "description": "",
                "assetType": "台式机",
                "assetName": "赛尔",
                "assetModel": "Z-01",
                "userAssetList": [
                    {
                        "userDTO": {
                            "confirmationDate": null,
                            "firstJobDate": null,
                            "id": "",
                            "userCount": 0,
                            "orgList": [],
                            "roleList": [],
                            "salaryTypeList": [],
                            "socialSecurityList": [],
                            "failCount": 0,
                            "name": "管理员",
                            "personalEmail": "932276768@qq.com",
                            "personalPhone": "",
                            "personalPhoneCountryCode": "86",
                            "lastSalary": 0,
                            "lastSalaryStartDate": null,
                            "currentSalary": 0,
                            "currentSalaryStartDate": null,
                            "birthDate": null,
                            "joiningDate": null,
                            "successCount": 0,
                            "locked": false,
                            "identified": true,
                            "active": false
                        },
                        "count": 3
                    },
                    {
                        "userDTO": {
                            "confirmationDate": null,
                            "firstJobDate": null,
                            "id": "",
                            "userCount": 0,
                            "orgList": [],
                            "roleList": [],
                            "salaryTypeList": [],
                            "socialSecurityList": [],
                            "failCount": 0,
                            "name": "沙琪玛",
                            "personalEmail": "zdygx951@163.com",
                            "personalPhone": "17328121234",
                            "personalPhoneCountryCode": "86",
                            "lastSalary": 0,
                            "lastSalaryStartDate": null,
                            "currentSalary": 0,
                            "currentSalaryStartDate": null,
                            "birthDate": null,
                            "joiningDate": null,
                            "successCount": 0,
                            "locked": false,
                            "identified": true,
                            "active": false
                        },
                        "count": 2
                    }
                ],
仅有的幸福
仅有的幸福

membalas semua(1)
学霸

Mengapa tidak? Kod anda tidak menukar satu baris pun:

var data = {
    "assets": [
    {
        "id": "001",
        "assetCount": 14,
        "availableCount": 9,
        "price": 2,
        "startDate": null,
        "age": 0,
        "description": "",
        "assetType": "台式机",
        "assetName": "赛尔",
        "assetModel": "Z-01",
        "userAssetList": [
        {
            "userDTO": {
                "confirmationDate": null,
                "firstJobDate": null,
                "id": "",
                "userCount": 0,
                "orgList": [],
                "roleList": [],
                "salaryTypeList": [],
                "socialSecurityList": [],
                "failCount": 0,
                "name": "管理员",
                "personalEmail": "932276768@qq.com",
                "personalPhone": "",
                "personalPhoneCountryCode": "86",
                "lastSalary": 0,
                "lastSalaryStartDate": null,
                "currentSalary": 0,
                "currentSalaryStartDate": null,
                "birthDate": null,
                "joiningDate": null,
                "successCount": 0,
                "locked": false,
                "identified": true,
                "active": false
            },
            "count": 3
        },
        {
            "userDTO": {
                "confirmationDate": null,
                "firstJobDate": null,
                "id": "",
                "userCount": 0,
                "orgList": [],
                "roleList": [],
                "salaryTypeList": [],
                "socialSecurityList": [],
                "failCount": 0,
                "name": "沙琪玛",
                "personalEmail": "zdygx951@163.com",
                "personalPhone": "17328121234",
                "personalPhoneCountryCode": "86",
                "lastSalary": 0,
                "lastSalaryStartDate": null,
                "currentSalary": 0,
                "currentSalaryStartDate": null,
                "birthDate": null,
                "joiningDate": null,
                "successCount": 0,
                "locked": false,
                "identified": true,
                "active": false
            },
            "count": 2
        }
        ]
    }
    ]
}

var datalist=[];
var dataDe = data.assets;
for(var i = 0;i<dataDe.length;i++){
    for(var j= 0;j<dataDe[i].userAssetList.length;j++){
        dataDe[i].userDtoName = dataDe[i].userAssetList[j];
        datalist.push(dataDe[i]);
    }
}
Muat turun terkini
Lagi>
kesan web
Kod sumber laman web
Bahan laman web
Templat hujung hadapan
Tentang kita Penafian Sitemap
Laman web PHP Cina:Latihan PHP dalam talian kebajikan awam,Bantu pelajar PHP berkembang dengan cepat!