简体   繁体   English

Javascript:从JSON读取值然后进入堆栈

[英]Javascript: Reading values from JSON then pushing into stack

I can read the json from calcList1 in the if statement, and thought I could just push them into the l=[] stack. 我可以在if语句中从calcList1读取json,并认为我可以将它们推入l = []堆栈。 I am not sure what I am missing here, Because I am getting an error. 我不确定我在这里缺少什么,因为我收到了错误。

error: 错误:

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

loop: 环:

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);

I think you don't need equal sign '=' in here but I'm not sure if this is the main issue in here: 我认为你在这里不需要等号'=',但我不确定这是否是这里的主要问题:

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
        });

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

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