首页 > 解决方案 > Firestore 不会在 jspdf 字符串上读取 \n

问题描述

我正在尝试在 jspdf 字符串上换行。问题是firestore不会将它( \n )识别为换行符,而是作为字符串。

我尝试过的解决方案:

\n\n , html br 标签

var string = "This is a sample lb\n text"
var string1 = string.replace("lb","\n")

doc.text(10,10, string1)
actual : This is a sample lb\n text

expected : This is a sample 
           text

标签: javascriptangularfirebasegoogle-cloud-firestore

解决方案


Cloud Firestore SDK 没有新行的问题,因此问题必须在您的代码中的其他地方。为了演示,我运行以下代码,将字符串写入文档,检索它,然后显示结果:

Chrome DevTools 控制台演示了正确的换行处理

代码:

db = firebase.firestore();
db.collection("lines").doc("newline").set({'myString': "This is a new\nline"});
x = db.collection("lines").doc("newline").get();
x.then(function(doc) {console.log(doc.data().myString)});

推荐阅读