Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(80)

Unified Diff: components/physical_web/webui/resources/physical_web.js

Issue 2741823002: Update Physical Web WebUI to show new results automatically (Closed)
Patch Set: remove renderID Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: components/physical_web/webui/resources/physical_web.js
diff --git a/components/physical_web/webui/resources/physical_web.js b/components/physical_web/webui/resources/physical_web.js
index 418dc1d6e90c1b5e8daffb35b8fbd841900eae08..c4504b08c3e4a92e0a17844a5dc838da5843ac80 100644
--- a/components/physical_web/webui/resources/physical_web.js
+++ b/components/physical_web/webui/resources/physical_web.js
@@ -9,8 +9,19 @@
* nearby devices
*/
function renderTemplate(nearbyUrlsData) {
+ // This is a workaround with jstemplate. Jstemplate render only works on empty
+ // node. When we need to rerender things, we have to remove previous nodes.
+ let renderContainer = document.getElementById('render-container');
+ // Remove existing childNode.
+ while (renderContainer.hasChildNodes()) {
+ renderContainer.removeChild(renderContainer.lastChild);
+ }
+
+ let templateDiv = document.getElementById('render-template').cloneNode(true);
+ renderContainer.appendChild(templateDiv);
+
// This is the javascript code that processes the template:
- jstProcess(new JsEvalContext(nearbyUrlsData), $('physicalWebTemplate'));
+ jstProcess(new JsEvalContext(nearbyUrlsData), templateDiv);
}
function requestNearbyURLs() {
@@ -22,7 +33,7 @@ function physicalWebItemClicked(index) {
}
function returnNearbyURLs(nearbyUrlsData) {
- var bodyContainer = $('body-container');
+ let bodyContainer = $('body-container');
renderTemplate(nearbyUrlsData);
bodyContainer.style.visibility = 'visible';

Powered by Google App Engine
This is Rietveld 408576698