Dynamically add page to Polymer iron-pages

落爺英雄遲暮 提交于 2019-12-11 10:10:57

问题


Is there any way to add a new page to iron-pages dynamically? I have this iron-pages:

<iron-pages selected="0">
  <div>Abc</div>
</iron-pages>

And then I add a couple more pages dynamically:

document.addEventListener("WebComponentsReady", function() {
  var newDiv = document.createElement("div");
  newDiv.innerHtml = "Def";
  var ironPage = document.querySelector("iron-pages");
  ironPage.appendChild(newDiv);
  console.log(ironPage.items.length) // log 1 instead of 2
  ironPage.select(1) // nothing shown.
});

回答1:


you might need to use the Polymer.Dom Api

Polymer.dom(ironPage).appendChild(newDiv);

Also I think you may have made another error:

instead of

newDiv.innerHtml = "def";

do

newDiv.textContent = "def";


来源:https://stackoverflow.com/questions/34501890/dynamically-add-page-to-polymer-iron-pages

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!