我正在使用 JS/JQUERY 创建一个“填空”客户端应用程序,它将读取从 AJAX 调用检索到的 XML 文件。
XML 内部是一个节点,该节点包含一个带有标签的字符串,这些标签标识字段的去向。
为了尝试改善 UI 体验,我正在使用 div 在网页上格式化此表单的显示,如下所示
<div id="prologue"></div>
<div id="message"></div>
<div id="epilogue"></div>
我想通读字符串并使用控制语句来检查该部分应该在上面提到的那些 div 中的位置。
这是来自文本节点的示例字符串
${Prologue} - 亲爱的 ${Title} ${Surname}。这是来自公司的消息。有人打电话但无法访问,已为 ${ProductName} 进行了新的预约,订单号为 ${VOLNumber},时间为 ${AppointmentDate},介于 ${AppointmentSlot} 之间。请确保您可以在您的场所为工程师提供服务。如果不方便,请在预约前一天中午 12:00 之前访问 thecompany.com 或致电 01111 1111 111。请参阅您的订单确认,了解当天会发生什么的详细信息。${尾声}
假设很简单,任何不是 ${Prologue} 或 ${Epilogue} 的东西都会进入“消息” div
我这里有伪代码
for loop through the string
if ${prologue} put inside prologue div tags
if !=$prologue and !=$epilogue then place in message div tag
if ${epilogue} then put inside epilogue div tags
我将在循环中创建一些其他规则,例如当一个“。” 字符然后插入换行标记
输出应该是这样的
<div id="prologue">
${prologue}
</div>
<div id="message">
Dear ${Title} ${Surname}. <br/>
This is a message from The Company. An person called but was unable to gain access, a new appointment has been made for ${ProductName} with order number ${VOLNumber}, on ${AppointmentDate} between ${AppointmentSlot}. <br/>
Please ensure you are available at your premises for the engineer. If this is not convenient, go to thecompany.com or call 01111 1111 111 before 12:00 noon the day before your appointment. Please refer to your order confirmation for details on what will happen on the day. <br/>
</div>
<div id="epilogue">
${epilogue}
</div>
有人可以确定我可以用于此实现的 javascript 或 jquery 中的哪些功能。我正在考虑使用 .map() jquery 函数,但是我不确定这是否适合我的情况。
请没有完整的代码解决方案!只是预告片,所以我可以自己解决!
编辑
这是我的未格式化显示的屏幕截图
谢谢