从文件中实现MaterializeCSS自动填充数据

时间:2019-02-11 07:06:34

标签: javascript materialize

我想从JSON文件将数据填充到MaterializeCSS自动完成功能。我的json文件看起来像这样:

{
  "Escherichia coli(562)": "https://pax-db.org/images/species/511145.jpg",
  "Oryza sativa(4530)": "https://upload.wikimedia.org/wikipedia/commons/1/19/Rice_Plants_%28IRRI%29.jpg",
  "Zea mays(4577)": "https://upload.wikimedia.org/wikipedia/commons/e/e3/Zea_mays_-_Köhler–s_Medizinal-Pflanzen-283.jpg"
}

我编写的javascript代码:

var organismData = {};
    $.getJSON('assets/data/organism_list_test.json', function(data) {
        $.each( data, function( key, val ) {
            organismData[key] = "'" + val + "'";
        });
    }).done(function() {
        var organismElement = $('#organismName');
        console.log(organismData);
        organismElement.autocomplete({
            data: organismData
        });
    });

我希望organismData像这样出现:

{
  "Escherichia coli(562)":'https://pax-db.org/images/species/511145.jpg',
  "Oryza sativa(4530)": 'https://upload.wikimedia.org/wikipedia/commons/1/19/Rice_Plants_%28IRRI%29.jpg',
  "Zea mays(4577)": 'https://upload.wikimedia.org/wikipedia/commons/e/e3/Zea_mays_-_Köhler–s_Medizinal-Pflanzen-283.jpg'
},

您可以在此处找到示例:https://materializecss.com/autocomplete.html

加载名称,但显示螺母图像:

Error enter image description here

我在这里要在此处获得正确的格式是什么问题?

谢谢。

0 个答案:

没有答案