我可以在if语句中从calcList1中读取json,并认为可以将它们压入l = []堆栈中。我不确定我在这里缺少什么,因为我遇到了错误。

错误:

"name": "TypeError",
"message": "'undefined' is not an object (evaluating 'l[0].z_param_name')",


环:

var calcList1 = require('ui/common/convertd/calcs_db/calcs_models/outSort2').calcs_list;

var l = [];
var x = 0;

for (var i = 0; i < calcList1.length; i++) {

    if (calcList1[i].z_clac_id == _args.z_dex) {
        //>>>>this works>>>>>> Ti.API.info('>>', calcList1[i].z_param_name)
        l.push = ( {
            z_clac_id : calcList1[i].z_clac_id,
            z_find : calcList1[i].z_find,
            z_param_id : calcList1[i].z_param_id,
            z_param_name : calcList1[i].z_param_name,
            z_param_unit : calcList1[i].z_param_unit
        });

    }
};

Ti.API.info('>>>>>>>>>>>>>>>>>>>>>>>>>>', l[0].z_param_name);

最佳答案

我认为您在这里不需要等号'=',但是我不确定这是否是这里的主要问题:

l.push( {
            z_clac_id : calcList1[i].z_clac_id,
            z_find : calcList1[i].z_find,
            z_param_id : calcList1[i].z_param_id,
            z_param_name : calcList1[i].z_param_name,
            z_param_unit : calcList1[i].z_param_unit
        });

09-25 19:25