* Forces the Repeater to reload all its items.
()
| 106 | * Forces the Repeater to reload all its items. |
| 107 | */ |
| 108 | public refresh() { |
| 109 | if (this.itemsLayout) { |
| 110 | this.itemsLayout.removeChildren(); |
| 111 | } |
| 112 | |
| 113 | if (!this.items) { |
| 114 | return; |
| 115 | } |
| 116 | |
| 117 | const length = this.items.length; |
| 118 | for (let i = 0; i < length; i++) { |
| 119 | const dataItem = this._getDataItem(i); |
| 120 | let viewToAdd = null; |
| 121 | |
| 122 | if (this._itemTemplateSelector && this.itemTemplates) { |
| 123 | const key = this._itemTemplateSelector(dataItem, i, this.items); |
| 124 | const length2 = this.itemTemplates.length; |
| 125 | for (let j = 0; j < length2; j++) { |
| 126 | const template = <KeyedTemplate>this.itemTemplates[j]; |
| 127 | if (template.key === key) { |
| 128 | viewToAdd = template.createView(); |
| 129 | break; |
| 130 | } |
| 131 | } |
| 132 | } |
| 133 | |
| 134 | if (!viewToAdd) { |
| 135 | if (__UI_USE_EXTERNAL_RENDERER__) { |
| 136 | viewToAdd = isFunction(this.itemTemplate) ? (<Template>this.itemTemplate)() : this._getDefaultItemContent(i); |
| 137 | } else { |
| 138 | viewToAdd = this.itemTemplate ? Builder.parse(this.itemTemplate, this) : this._getDefaultItemContent(i); |
| 139 | } |
| 140 | } |
| 141 | |
| 142 | viewToAdd.bindingContext = dataItem; |
| 143 | this.itemsLayout.addChild(viewToAdd); |
| 144 | } |
| 145 | |
| 146 | this._isDirty = false; |
| 147 | } |
| 148 | |
| 149 | public _onItemsChanged(data: ChangedData<any>) { |
| 150 | // TODO: use the event args and optimize this code by remove/add single items instead of full rebuild. |
no test coverage detected