Dynamically add page to Polymer iron-pages

2019-08-07 08:49发布

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.
});

标签: polymer-1.0
1条回答
戒情不戒烟
2楼-- · 2019-08-07 09:18

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";
查看更多
登录 后发表回答