angular - How to Store and Retrieve Data in Multidimensional Array in Angular4 / Ionic 3 -
i trying store values in angular 4 (ionic 3) , fetch row array based on key. key passed function , function retrieves values compute values. class property below. pretty sure formatted right.
let chemicals = [{ "trichlor" : [{ "ozmul": 6854.95, "volume": "x" }], "dichlor": [{ "ozmul": 4149.03, "volume": 0.9351 }], "cal-hypo-48": [{ "ozmul": 3565.44, "volume": 0.9352 }], "cal-hypo-53": [{ "ozmul": 3936.84, "volume": 0.9352 }], "cal-hypo-65": [{ "ozmul": 4828.12, "volume": 0.9352 }], "cal-hypo-73": [{ "ozmul": 5422.41, "volume": 0.9352 }], "lithium-hypo": [{ "ozmul": 2637.5, "volume": 0.978 }], "chlorine-gas": [{ "ozmul": 7489.4, "volume": "x" }] }];
so basically, need grab value passed function (let's use trichlor example). need able use value fetch ozmul , volume values associated trichlor. proper way accomplish within provider? below example of code function uses values:
chemical = "trichlor"; // passed function if (chemicals.chemical.ozmul == 'x') { let tempvaluetwoweight = 'unknown'; } else { let tempvaluetwovolume = (tempvaluetwo * chemicals.chemical.volume) }
some thing suit , not need hardcode paths
test(val:string){ this.chemicals.foreach(data => { let value = data[val].find(data => data.volume === 'x'); console.log(value); }); }
have method pass val want search , data.volume parameter can made dynamic , check
Comments
Post a Comment