简体   繁体   English

所有收藏的Firestore清单

[英]Firestore list of all collections

I have a list of json fieldnames in an array say.. 我在数组中有一个json字段名列表。

eventVariables = ['customerName','date','amount'].

My JSON looks like.. 我的JSON看起来像..

info = {
'customerName':'Ashish Maity',
'date': '14-04-18',
'amount':'500'
}

Now I want send message to that customer, my message template is like: 现在,我想向该客户发送消息,我的消息模板如下:

smsBody = 'Dear customerName, we have received Rs.amount on date';

Now my requirement is I want to replace the variables(customerName,amount and date) in the smsBody with the value in the info JSON. 现在我的要求是我想用info JSON中的值替换smsBody中的变量(customerName,amount和date)。

My code:
for(let i=0; i<eventVariables.length; i++){
 finalSmsBody = smsBody.replace(eventVariables[i],info[eventVariables[i]]);
};

My Output:
Dear customerName, we have received Rs.amount on 14-04-18

Only the last variable(date) gets replaced with the JSON value..I want that all the variables should be replaced with respective JSON value 只有最后一个变量(日期)被替换为JSON值。我希望所有变量都应被替换为各自的JSON值

Try this code 试试这个代码

for(let i=0; i<eventVariables.length; i++){
  smsBody= smsBody.replace(eventVariables[i],info[eventVariables[i]]);
};

How about : 怎么样 :

for (var key in info ){
   smsBody.replace(key,info[key])
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM