我有一个填充的 mysql 数据库,它输出 json 数据,这些数据通过 angularjs 消费和显示。 数据库中的一些文本字符串具有转义引号和双引号,例如:
Do you have at least a bachelor\'s degree in child development?
或
asking the children to address you as \"Ma\'am\" or \"Sir\" to formalize things
问题是 angularjs 仍然显示带有转义引号的字符串。避免这种情况的最佳方法是什么?我是否在数据库上进行搜索和替换,将转义子字符串(\',\")替换为其他内容? 输出显示在 angularjs 中,就像使用 ng-model 指令一样:
...
<div class="bs form-group" ng-if="quiz.quizmanager.quiz.questions[quiz.activeQuestion].quiz_question_type === 'text'">
<input type="text" class="form-control" ng-model="quiz.quizmanager.quiz.questions[quiz.activeQuestion].answer"
ng-change="quiz.selectAnswer(0, quiz.quizmanager.quiz.questions[quiz.activeQuestion].quiz_question_type)"
/>
</div>
...
最佳答案
我通过在重新填充数据库之前进行搜索和替换 sql 来解决这个问题
关于javascript - 解决数据库中转义字符的最佳方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46163438/