Dynamic input with select2 javasript with data get from database

How to make dynamic input with select2 and javascript that data get from database like this figure

I try to make with javascript, i try with dynamic input in javascript, i make variable function html but the database product get all that make the browser slowly respons because load a lot of data.