Polymer 1.0 - 如何绑定html值

Bao*_* Le 9 polymer

我有一个项目列表,其中每个项目的.content html值如下所示.

  <template is="dom-repeat" items="{{entries}}">
    <li><p class="paper-font-body2">{{item.title}}</p>
      <div>{{item.content}}</div></li>
  </template>
Run Code Online (Sandbox Code Playgroud)

内容字段有点像这样

  Hello <strong>Polymer</strong>
Run Code Online (Sandbox Code Playgroud)

它在浏览器中显示为纯文本.如何将其显示为安全的HTML?

编辑:这个问题被提出,但它没有帮助我.

Pet*_*ter 19

你可以很容易地做到:

<template is="dom-repeat" items="{{entries}}">
    <li><p class="paper-font-body2">{{item.title}}</p>
      <div inner-h-t-m-l="{{item.content}}"></div></li>
  </template>
Run Code Online (Sandbox Code Playgroud)

这就是我正在使用的,请记住XSS漏洞是开放的.


eva*_*dor 6

你可以尝试这样的事情:

<dom-module id="echo-html">

  <template>
    <span>{{html}}</span>
  </template>

  <script>
    Polymer({
      is: 'echo-html',
      properties: {
          html: {
              type: String,
              value: 'html'
          }
      },
      ready: function() {
          this.innerHTML = this.html;
      }
    });
  </script>

</dom-module>
Run Code Online (Sandbox Code Playgroud)

并且像我猜的那样称呼它:

<div><echo-html html="{{item.content}}"></echo-html></div>
Run Code Online (Sandbox Code Playgroud)