Javascript Array

-1

People would like to know how to search for an image instead of color in this javascript array below Instead:

<script>
  array var arrDados = [{title: "Dados 1", value: 1, **color**: "#fe4400"}]
</script>

I wanted to change to search for image, but the form below is not correct:

<script>
    var arrDados = [ {title: "Dados 1", value: 1, background-image: "www.site.com.br/imagem/figura.png"}]
</script>

Where color drawing takes an image. Thank you for your help

    
asked by anonymous 02.06.2018 / 19:52

1 answer

0

If you want to add background-image s to a vector that has color s, you can do as follows:

$.each(arrDados, function (i, o) {

    switch (o.color) {
        case '#fe4400':
            o['background-image'] = 'http://www.meusite.com.br/img/figura-do-fe4400.jpg';
            break;
        case '#de4400':
            o['background-image'] = 'http://www.meusite.com.br/img/figura-do-de4400.jpg';
            break;
        case ...
                                   ....
            break; 
    }
    o.color = undefined;

});

And if your question concerns the Fiddle that made here , it probably does not accept images because it is an image rasterized.

    
02.06.2018 / 21:12