【问题标题】:Create a single VCard file with multiple entries using javascript使用 javascript 创建具有多个条目的单个 VCard 文件
【发布时间】:2019-04-13 10:48:36
【问题描述】:

我使用了来自 github gist 的代码,它允许您将单个内容保存到 VCF 文件中。

<!doctype html>
<html>
    <head>
       <script type="text/javascript" src="vcard2.js"></script>
    </head>
    <script type="text/javascript">
        // From JSON
        var johnSmith = {
            "version": "4.0",
            "n": "SMITH;John;;",
            "fn": "John Smith",
            "nickname":"js",
            "title": "Missing man too",
            "tel": [
                {"value": "555-555-555", "type": "cell"}
            ],
            "email": [
                { "value": "john.smith@work.com", "type": "work" },
                { "value": "john.smith@home.com", "type": "home" }
            ]
        }
        var link = vCard.export(johnSmith, "John Smith", false) // use parameter true to force download
        document.body.appendChild(link)
        </script>
    </body>
</html>

这适用于作为文件的单一内容,请参阅JSfiddle。 我的问题是如何将多个内容添加到同一个 VCF 文件中。

【问题讨论】:

    标签: javascript json vcf-vcard


    【解决方案1】:

    在您提供的小提琴中,只需编辑 dump() 函数以接受数组。然后迭代数组并执行完全相同的操作,将输出(用\n 拆分)组合成一个变量。

        dump: function(cards) {
            var cardsLength = cards.length;
            var cardsStr = "";
    
            for (var cardsIndex = 0; cardsIndex < cardsLength; cardsIndex++) {
    
                var card = cards[cardsIndex];
                //...existing code... just remove the return
                 cardsStr+=str+"\n";
            }
            return cardsStr;
        }
    

    现在调用vCard.export() 并传递一个对象数组而不是对象。

    在这里试试:JSFiddle

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-08-01
      • 2019-03-21
      • 1970-01-01
      • 2021-03-18
      • 1970-01-01
      • 2023-01-26
      • 2018-09-29
      相关资源
      最近更新 更多