2017-07-19 113 views
2

如何將飛鏢中的2個或多個地圖合併/合併到1個地圖中? 比如我有這樣的:將多個地圖合併/合併爲1個地圖

var firstMap = {"1":"2"}; 
var secondMap = {"1":"2"}; 
var thirdMap = {"1":"2"}; 

我想:

var finalMap = {"1":"2", "1":"2", "1":"2"}; 

回答

3

可以使用addAll方法Map對象的

var firstMap = {"1":"2"}; 
var secondMap = {"2":"3"}; 

var thirdMap = {}; 

thirdMap.addAll(firstMap); 
thirdMap.addAll(secondMap); 

print(thirdMap); 

或者

var thirdMap = {}..addAll(firstMap)..addAll(secondMap); 
+0

有沒有辦法,雖然這些文件全部合併在同一行? – smriti

+2

var finalMap = {} .. addAll(firstMap).. addAll(secondMap).. addAll(thirdMap); –

+0

是用'..'更新了迴應 –

2

另一種選擇是使用CombinedMapViewpackage:collection

new CombinedMapView([firstMap, secondMap]) 

它不創建一個合併的地圖,但創建一個Map這是一個鑑於兩者