Heim > Fragen und Antworten > Hauptteil
P粉3015232982023-08-04 09:03:48
这样的吗
// Assuming you have the testMap already defined // testMap: Map<string, any> // Step 1: Get the selected key from the dropdown (replace 'selectedKey' with the actual selected key) const selectedKey = 'someKey'; // Step 2: Retrieve the corresponding object from the map const selectedObject = testMap.get(selectedKey); // Step 3: Update the "name" property of the object if (selectedObject) { selectedObject.name = selectedKey; } else { // Handle the case when the selected key is not found in the map console.error('Selected key not found in the map!'); } // Step 4: Set the updated object back into the map using the same key testMap.set(selectedKey, selectedObject); // Now, the "name" property of the selected object in the map should be updated to the selected key.