我想更改地图中键的值。我该怎么做呢?有可能吗?
我只找到了方法insert(_key,_value),但是我不想创建带有值的新键,而是更改现有键的值。
发布于 2016-10-10 09:20:08
如何编辑键
只需移除旧键,然后用新键重新插入。
map = new Map(Types::String,Types::Real)
map.insert("a", 1);
map.insert("b", 2);
map.insert("c", 3);
map.remove("b"); // remove key
map.insert("y", 2); // reinsert new key with value如何编辑值
只需用插入重新插入值即可。键不能有重复项,而只能覆盖。
返回值 类型:布尔型 如果映射中不存在并已插入密钥,则为true;否则为false。 备注 如果该键已经存在于映射中,则更新该值。
例如,要在项目组上手动和行数量分组:
Map map = new Map(Types::String,Types::Real);
SalesLine sl;
while select sl where sl.SalesId == "123"
{
map.insert(sl.ItemGroup, sl.LineAmount + (map.exists(sl.ItemGroup) ? map.lookup(sl.ItemGroup) : 0);
}相当于但在性能上不如:
select sum(LineAmount) sl group ItemGroup where sl.SalesId == "123";发布于 2020-10-21 14:20:33
在插入另一个值(即更新键的值)之前,不需要删除键。只需再次调用insert()即可。
在SQL术语中,“‘insert()”更准确地称为'upsert()’。
Map mymap;
mymap.insert('a',1.0);
mymap.insert('a',1.1);
info(strFmt('%1',mymap.lookup('a'))); // will return '1.1'https://stackoverflow.com/questions/39952705
复制相似问题