这两个数组有什么区别,为什么typeahead w / autoform只能与其中一个一起使用?

时间:2016-10-11 12:31:31

标签: meteor underscore.js typeahead.js meteor-autoform

这是我的SimpleSchema:

confirmedAddress: {
    //addressRecordID
    type: String,
    label: "Address",
    optional: true,
    autoform: {
        type: "typeahead",
        /*
        options: function() {
            return [{
                label: "2013",
                value: 2013
            }, {
                label: "2014",
                value: 2014
            }, {
                label: "2015",
                value: 2015
            }]
        }
        */
        options: function() {
            var addresses = Addresses.find({
                houseNumber: "0"
            }).map(function(address) {
                return {
                    label: address.houseNumber + " " + address.street + ", " + address.unit + ", " + address.city,
                    value: address._id
                };
            });
            /*console.log("addresses",addresses)*/
            var addresses2 = [{
                "label": "0 Unknown, undefined, undefined",
                "value": "rec2I5yyHm6rSQOAO"
            }, {
                "label": "0 unknown, undefined, undefined",
                "value": "recBEYzyvjfCm0D4k"
            }, {
                "label": "0 Unknown, undefined, undefined",
                "value": "recFdDsCzYgXGWWyC"
            }, {
                "label": "0 SE Muskogee Ave, undefined, undefined",
                "value": "recH0g6UvLrztSCCR"
            }, {
                "label": "0 Unknown, undefined, undefined",
                "value": "recK8aT6gQoRsqDVP"
            }, {
                "label": "0 unknown, undefined, undefined",
                "value": "recKstPZAt5wrGzRT"
            }, {
                "label": "0 Unknown, undefined, undefined",
                "value": "recSf7X7LLIWqvvGK"
            }, {
                "label": "0 Unknown, undefined, undefined",
                "value": "recbUExSc2Rd1kFSp"
            }, {
                "label": "0 Oak, undefined, undefined",
                "value": "recekb3FlD6vghcf0"
            }, {
                "label": "0 Unknown, undefined, undefined",
                "value": "rechiCWJ9ScAeBOC4"
            }, {
                "label": "0 Unknown, undefined, undefined",
                "value": "reclUGe2NkeLSafWj"
            }, {
                "label": "0 unknown, undefined, undefined",
                "value": "reclsD03UdhBwLc6b"
            }, {
                "label": "0 Moved out of territory, undefined, undefined",
                "value": "recrLqh76Qk7EHQcm"
            }, {
                "label": "0 Unknown, undefined, undefined",
                "value": "recyyDLXMkHMRf9bn"
            }]
            console.log(addresses, addresses2)
            console.log("addresses == addresses2", addresses == addresses2) // false
            return addresses2
        }
    }
}

第一个评论部分工作正常。返回addresses2也可以。但是,当我返回addresses时,typeahead不起作用。

问题是,我通过将其粘贴到控制台然后将其复制到代码中来获得addresses2

Addresses.find({
    houseNumber: "0"
}).map(function(address) {
    return {
        label: address.houseNumber + " " + address.street + ", " + address.unit + ", " + address.city,
        value: address._id
    };
});

我在这里缺少什么?

1 个答案:

答案 0 :(得分:0)

问题是,当创建html表单时,addresses是一个空数组,因为它正在创建。 addresses2是硬编码的,因此可立即使用。