0

收到上述错误参考线for ( var i = 0; i < base.contacts.length; i++) {,无法弄清楚如何解决。下面是相关的代码部分

 synckolab.addressbookTools.createTBirdObject = function (base, cards) {
    var card = null;
    if (base.type === "contact") {
        card = Components.classes["@mozilla.org/addressbook/cardproperty;1"].createInstance(Components.interfaces.nsIAbCard);
    } else if (base.type === "maillist") {
    card = Components.classes["@mozilla.org/addressbook/directoryproperty;1"].createInstance(Components.interfaces.nsIAbDirectory);
    card.isMailList = true;
    } else {
        return null;
    }

// for a mailing list add the entries
    if (base.type === "maillist") {
    card.dirName = this.getCardProperty(base, "DisplayName");
    if (this.haveCardProperty(base, "NickName")) {
        card.listNickName = this.getCardProperty(base, "NickName");
    }
    if (this.haveCardProperty(base, "Notes")) {
        card.description = this.getCardProperty(base, "Notes");
    }
    // fill the list
    for ( var i = 0; i < base.contacts.length; i++) {
        var listCard = cards.get(this.getUID(base.contacts[i]));
        card.addressLists.appendElement(listCard, false);
    }
} else {
    // go through all elements of base
    for ( var field in base) {
        // skip our own stuff TODO: handle mailing lists!
        if (field !== "type" && field !== "synckolab" && field !== "ts" && field !== "contacts" && field !== "isMailList") {
            // copy the property from base to card
            this.setCardProperty(card, field, this.getCardProperty(base, field));
        }
    }
}

return card;

};

4

1 回答 1

0

base是您移交给函数的参数,该函数应该是具有(至少)以下属性的对象:

type
contact

显然它缺少contact属性,它又应该是一个数组。因此,您应该查看要移交给该函数的对象。

要暂时解决此问题,您可以执行以下操作:

if (base.contacts){
    for ( var i = 0; i < base.contacts.length; i++) {
        /*...*/
    }
}

但是,要真正解决问题,您应该查看代码、调用函数的位置并检查您传递给函数的对象是如何构造的。做一个

console.log(base);

仔细观察物体。

于 2012-10-10T14:50:52.413 回答