0
A
回答
1
Angular內部使用for..in
運算符遍歷非數組對象。 Proof-link to the sources。 Map
和Set
不能通過這種方式迭代,它們應該通過for..of
迭代。所以你不能使用這個集合ng-repeat
沒有任何額外的轉換。
即將到來的Angular 2有ES6功能的支持,它也有for..of語法重複。有關更多詳細信息,請參閱angular 2 docs。
0
我試圖在Angular 2中綁定Map
到ng-repeat
。即使使用*ngFor="let item of items"
,它也不起作用。相反,這解決了我的問題:
/*
* Extension of the ES6 map, which also supports binding to it's array of values
*/
class BindableMap extends Map {
constructor(...args) {
super(...args);
this.bindableValues = [];
}
updateBindableValues() {
// Clear the array without creating a new one.
this.bindableValues.length = 0;
// Push all the new values
this.bindableValues.push(...Array.from(super.values()));
}
clear(...args) {
super.clear(...args);
this.updateBindableValues();
}
set(...args) {
super.set(...args);
this.updateBindableValues();
}
delete(...args) {
super.delete(...args);
this.updateBindableValues();
}
}
這樣你就可以用ng-repeat="value in map.bindableValues"
也使用它的角1.x中。
請注意,這不是最有效的解決方案,因爲每次更改地圖時都會重新創建可綁定值。儘管如此,我的目的是足夠的。另外,如果您願意,還可以將BindableMap
擴展爲綁定到鍵或鍵值對。
相關問題
- 1. 數據綁定到對象 - 如何更新對象/綁定?
- 2. 在Set集合中綁定對象
- 3. 通過formview綁定和更新對象
- 4. 刷新winform控件綁定綁定到綁定到對象的數據源更改後的對象
- 5. 更新綁定到對象[屬性](Binding.IndexerName怪異)的綁定
- 6. 如何綁定到一個對象
- 7. 如何將jsonResult對象綁定到jqgrid?
- 8. 如何正確綁定到子對象?
- 9. 如何從Xaml綁定對象到treeview
- 10. 如何將外鍵綁定到對象?
- 11. 如何將對象綁定到treeview?
- 12. Leaflet Draw + Angular + GeoJSON:如何在Map和GeoJSON對象之間實現雙向綁定
- 13. 如何將對象綁定到ComboBox,但在更改時更新其他對象?
- 14. 將HashTable/Map綁定到Jtable
- 15. 更新綁定對象時ContentPresenter的綁定未更新
- 16. 如何發出Map對象
- 17. 綁定到具有空對象和「變化」對象的集合
- 18. C#。將對象綁定到對象
- 19. 如何將FormGroup對象綁定到ModelClass對象
- 20. 如何在運行時將TClientDataset對象綁定到TGrid對象?
- 21. 參考和綁定對象
- 22. 綁定對象DropdownlistFor和Submitform
- 23. WPF綁定到對象
- 24. 綁定到對象屬性
- 25. 綁定到子對象
- 26. XAML綁定到對象
- 27. 綁定對象到Gridview
- 28. DetailsView綁定到子對象
- 29. JSON綁定到Javascript對象
- 30. 綁定對象到FormGroup - ng2
你試過了,失敗了嗎? – zerkms
我想你談談Angular 1.3? –
是和是....... – Uri