我有一个JSON文件,其中一些元素包含html代码并尝试将其加载到Polymer元素中。但是,Polymer将html呈现为纯文本。如何让Polymer将html代码呈现为html?
示例JSON数组:
[
{
"id" = "nr1",
"content" = "some text with <i>italic</it> parts"
}, {
"id" = "nr2",
"content" = "some text with <span class="test">formatted</span> parts"
}
]
聚合物元素:
<link rel="import" href="/bower_components/polymer/polymer.html">
<link rel="import" href="/bower_components/iron-ajax/iron-ajax.html">
<dom-module id="load-epi">
<style>
</style>
<template>
<iron-ajax
auto
url="epigraphs.json"
handle-as="json"
last-response="{{epigraphs}}"></iron-ajax>
<div class="test">
<div class="selectedcontent">
<p>{{selected.content}}</p>
<p class="selectedid">{{selected.id}}</p>
</div>
</div>
</template>
<script>
Polymer({
is: 'load-epi',
properties: {
epigraphs: {
type: Array,
notify: true,
value: function(){return []}
},
selected: {
type: Array,
computed: 'selectEpigraph(epigraphs)'
}
},
selectEpigraph: function(epigraphs) {
var epi = Math.floor((Math.random() * epigraphs.length));
return epigraphs[epi]
}
});
</script>
</dom-module>