我有一个名为 Current_Address__c 的自定义字段,其数据类型为 textarea。
我需要按以下格式填充此字段。即街道后的换行符和zip后的另一个换行符。
街道 城市 国家 邮编 国家
城市国家邮政编码国家等的值取自联系对象。我不想将其用作公式字段。所以我需要在我的控制器中填充它并在我的 VF 页面上显示它。
我正在尝试使用下面的代码添加换行符
this.customobj.Current_Address__c = currentStreet + '\\n ' + currentCity + ' ' + currentState + ' ' + currentZIP + '\\n ' + currentCountry ;
我也使用了 \n 而不是 \n。
它仍然以一行而不是 3 行显示该字段
编辑
我使用以下代码完成了这项工作。我会接受 mathews 的答案,因为它可以与 outputfield 一起使用。
currentAddress = currentStreet;
currentAddress += '\r\n';
currentAddress += currentCity + + ' ' + currentState + ' ' + currentZIP ;
currentAddress += '\r\n';
currentAddress += currentCountry;
这仅在您使用 += 时有效。不知道为什么会这样