如何遍历 JSON,遍历 DOM 和 JSON 以将 json 元素与 DOM 中的元素匹配?
我有html:
<div class="input alpha grid_4">
<label for="enterEmail">Email Address<label>
<input id="enterEmail" name="enterEmail" type="text" />
<span class="validMark"></span>
</div>
json渲染后我想要它:
<div class="input alpha grid_4">
<label for="enterEmail">Email Address <a class="toolTip" href="#" title=" By providing us with an email address for your user name, you are more likely to remember it."></a></label>
<input id="enterEmail" name="enterEmail" type="text" />
<span class="validMark"></span>
<div class="helperText">john@test.com</div>
</div>
和json:
[
{
“field”: “enterEmail”,
“contextHelpText”: “By providing us with an email address for your user name, you are more likely to remember it.”,
“helperText”: “john@test.com”
},
{
“field”: “billAddress1”,
“contextHelpText”: “Please enter the address associated with your billing information.”
}
]
我在概念化循环如何运行时遇到问题,如果 json 中不存在 helpertext 或 contexHelpText,如何解决这个问题。(将它们放在json中会更好,但没有价值吗?)