jfriedman823 / jquery_multi-select_crossover

A simple multi-select crossover for forms built with jquery
https://jfriedman823.github.io/jquery_multi-select_crossover/index.html
MIT License
2 stars 0 forks source link

can you tell me how can i loop through an arry from database instead of hard coded items #1

Open Shafeenes opened 4 years ago

Shafeenes commented 4 years ago

Items

var Data = ['Chaperone', 'Jade Rabbit', 'Wardcliff Coil',
                'Tractor Cannon', 'Sweet Business', 'Thorn',
                'Graviton Lance', 'Wavesplitter', 'Telesto',
                'Black Splindle', 'Polaris Lance', 'Ace of Spades'];

    populateItems(Data, '#items');
<body >
    <div class="row text-center">
        <h1 >Selected Commands for Router</h1>
        <div class="col-md-3 col-md-offset-2">
            {% if devicetypecommands %}

            {% for devicetypecommand in devicetypecommands %}
            <h5 >Device Type {{ devicetypecommand.devicetypename }}</h5>

             <select multiple class="form-control crossover-box" id="items"></select>
            {% endfor %}
        </div>
        {% else %}
        <p class="no-devicetypecommands text-primary">No device type commands added yet.</p>
        {% endif %}

modified



populateItems(devicetypecommands.commmand , '#items');
jfriedman823 commented 4 years ago

The function “populateItems” is expecting an array of strings. What format is the data coming from DB? If you’re using an array of objects you can either modify “generateOptionElements” to target arr[i].objectProperty or push the strings to an arr that you feed into “populateItems”.