var data = [{
label: '分类一',
value: '0'
}, {
label: '分类二',
value: '1'
}, {
label: '分类三',
value: '2'
}, {
label: '分类四',
value: '3'
}, {
label: '分类五',
value: '4'
}, {
label: '分类六',
value: '5'
}]
<p class="text">
<span>0</span>
<span>1</span>
<span>2</span>
<span>3</span>
<span>4</span>
<span>5</span>
</p>
Please tell me how to render the corresponding label value in dom based on the value in the data in the simplest way? ? The data is uncertain, there may be more than ten or twenty
in it
The method above can be done, but this is equivalent to registering a variable every time, adding a span node to .text every time, and manipulating the DOM, which causes a lot of overhead! I personally recommend using the following method.
The methods above are all feasible, but the first two methods have their own advantages and disadvantages in performance under Firefox and Chrome. Now the common practice is to create a new blank document fragment (DocumentFragment).