因此,我正在尝试创建一个相对简单的字典,请参见下面的片段:
var res = {"id":$( "#chose_partner option:selected" ).val(),
"name":$( "#chose_partner option:selected" ).text()};
var_current_partner_id = $("#chose_partner option:selected").val();
try{
//if dictionary already has the "trip_stop" key then append value to its value as its a list
var_user_record.trip_info['trip_stops'].push('res');
console.log('found stops so adding %o ', var_user_record);
}catch (e){
//if "trips_stop" doesn't exist then declare it as a list and append my value
console.log('error looking for specific trip %o %o %o ',var_user_record['trip_info'],var_user_record.trip_info,var_user_record);
var_user_record['trip_info']['trip_stops'] = [];
var_user_record['trip_info']['trip_stops'].push(res);
}
如果字典已经具有“ trip_stop”键的逻辑,则将值附加到其值作为列表。
如果“ trips_stop”不存在,则将其声明为列表并附加我的值。
输出是如此出乎意料,请参见下文
这是两件事