jQuery UI Widgets Forums Lists ListBox problem when getItems

This topic contains 3 replies, has 2 voices, and was last updated by  Nadezhda 9 years, 8 months ago.

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
  • problem when getItems #70848

    hongthach
    Participant

    after add item, from listbox1 to listbox2
    then var items = $(“#jqxWidget-2”).jqxListBox(‘getItems’);
    items[0].originalItem alway = null? why?
    but getItem from listbox1 then ok
    i think have problem at fuction addItem, or someone can fix it

    problem when getItems #70853

    Nadezhda
    Participant

    Hello hongthach,

    Here is an example which shows how to add item to listbox2 when select it from listbox1 and how to get items in listbox2 after the item is added. I hope it will be helpful to you.

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <title></title>
        <link rel="stylesheet" href="../../jqwidgets/styles/jqx.base.css" type="text/css" />
        <script type="text/javascript" src="../../scripts/jquery-1.11.1.min.js"></script>
        <script type="text/javascript" src="../../jqwidgets/jqxcore.js"></script>
        <script type="text/javascript" src="../../jqwidgets/jqxbuttons.js"></script>
        <script type="text/javascript" src="../../jqwidgets/jqxscrollbar.js"></script>
        <script type="text/javascript" src="../../jqwidgets/jqxlistbox.js"></script>
        <script type="text/javascript">
            $(document).ready(function () {
                var source = [
                    "Affogato",
                    "Americano",
                    "Bicerin",
                    "Breve",
                    "Café Bombón",
                    "Café au lait",
                    "Caffé Corretto",
                    "Café Crema",
                    "Caffé Latte",
                    "Caffé macchiato",
                    "Café mélange",
                    "Coffee milk",
                    "Cafe mocha",
                    "Cappuccino",
                    "Carajillo",
                    "Cortado",
                    "Cuban espresso"
                ];
                var source2 = [
                    "Espresso",
                    "Eiskaffee",
                    "The Flat White",
                    "Frappuccino",
                ];
    
                // Create a jqxListBox
                $("#jqxListBox").jqxListBox({ source: source, width: 200, height: 250 });
                $("#jqxListBox2").jqxListBox({ source: source2, width: 200, height: 250 });
                $("#jqxButton").jqxButton({});
                $('#jqxButton').on('click', function () {
                    var item = $("#jqxListBox").jqxListBox('getSelectedItem');
                    $("#jqxListBox2").jqxListBox('addItem', item.label);
                    var items = $("#jqxListBox2").jqxListBox('getItems');
                    var log = "";
                    for (var i = 0; i < items.length; i++) {
                        log += items[i].label; 
                        if (i < items.length - 1) log += ', ';
                    }
                    alert("Items: " + log);
                });
            });
        </script>
    </head>
    <body>
        <div>
            <div id='jqxListBox' style='float: left;'>
            </div>
            <div id='jqxListBox2' style='float: left; margin-left: 30px;'>
            </div>
        </div>
        <br />
        <div>
            <input style="margin-top: 280px; margin-left: -200px;" type="button" id='jqxButton' value="Button" />
        </div>
    </body>
    </html>

    Best Regards,
    Nadezhda

    jQWidgets team
    http://www.jqwidgets.com/

    problem when getItems #70866

    hongthach
    Participant

    pls look at my comment
    `source type json
    //{[id:123,name:’samle’,…]}
    $(“#copy-shop”).click(function(e){
    e.preventDefault();
    var items = $(“#jqxWidget-shop-source”).jqxListBox(‘getSelectedItems’);
    if(items){
    for (var i = 0; i < items.length; i++) {

    $(“#jqxWidget-shop-source”).jqxListBox(‘removeItem’, items[i] );
    //console.log(items[i].originalItem);
    // out ojb
    $(“#jqxWidget-shop-target”).jqxListBox(‘addItem’, items[i]);

    }

    }

    render();
    });

    function render(){
    var shop_list = new Array();
    var user_list = new Array();
    var items = $(“#jqxWidget-shop-target”).jqxListBox(‘getItems’);
    for (var i = 0; i < items.length; i++) {
    console.log(items[i].originalItem)
    //here alway out null.
    if( typeof items[i].originalItem=== “undefined”){

    user_list.push(items[i].value);

    }
    if(typeof items[i].originalItem=== “undefined”){
    shop_list.push(items[i].value);
    }

    }

    $(‘input[name=”list-shop-id”]’).val(shop_list.join(‘,’));

    $(‘input[name=”list-user-id”]’).val(user_list.join(‘,’));

    }`

    problem when getItems #70902

    Nadezhda
    Participant

    Hi hongthach,

    Please, provide us with a full sample(or jsfiddle example) so we will be able to test with your code.

    Best Regards,
    Nadezhda

    jQWidgets team
    http://www.jqwidgets.com/

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.