Jellfedora
Jellfedora

Reputation: 23

How to add content in property dynamically?

I have this code:

var fileInput = $("#input-id").fileinput({

        initialPreview: [
            "<img src ='https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_92x30dp.png' style='width:213px;height:141px;' name='Google'>",
        ],
    });

I want to add more img's (that I get from a JSON) to the initialPreview property, but I do not see how to access it. I do not even know how to make a log console of this property.

Upvotes: 1

Views: 70

Answers (1)

Bilal Siddiqui
Bilal Siddiqui

Reputation: 3629

Declare initial Data as:

var data = {
    initialPreview: [
        "<img src ='https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_92x30dp.png' style='width:213px;height:141px;' name='Google'>",
    ],
};

Now you fileinput will be

var fileInput = $("#input-id").fileinput(data);

When you get more value eg. new_img_data from JSON then

data.initialPreview.push(new_img_data)

now reload:

$("#input-id").fileinput(data)

Upvotes: 1

Related Questions