当tabout事件触发时我想在当前行下添加新行。但是没有加载组合框?

时间:2015-05-26 14:19:57

标签: javascript jquery ajax html5

Html代码:

下面的图片描述了我的输出。请帮助我解决这个问题。

<table class="table table-striped table-bordered table-hover table-condensed tableSiteUser">
                    <thead>
                        <tr>
                            <th>#</th>
                            <th>SiteName</th>
                            <th>UserName</th>
                            <th>Channel</th>
                            <th>Action</th>
                        </tr>
                    </thead>
                    <tbody id="site-table-body">
                        <tr>
                            <td class="countsiteuser">1</td>
                            <td><select class="form-control" id="siteContainer"></select>
                            </td>
                            <td><input type="checkbox" value="user" id="checkboxbutton"><input type="text" class="and" disabled placeholder="Default"/></td>
                            <td><input type="text" class="form-control" placeholder="Enter the Channel"/></td>
                            <td><span class="form-control glyphicon glyphicon-trash"></span></td>
                        </tr>
                   </tbody>
                </table>

JavaScript的:

$('.tableSiteUser').on('keydown','td:nth-child(4)',function(e){
            var keyCode=e.keyCode || e.which;

            if(keyCode == 9){
                serialUserSite++;
                $('tbody#site-table-body').append('<tr>'
                        +'<td class="beer" contenteditable="false">'+serialUserSite+'</td>'
                        +'<td><select class="form-control" id="siteContainer">'
                        +'</select></td>'
                        +'<td><input type="checkbox" value="user" id="checkboxbutton"><input type="text" class="and" disabled placeholder="Default"/></td>'
                        +'<td><input type="text" class="form-control" placeholder="Enter the Channel"/></td>'
                        +'<td><span class="glyphicon glyphicon-trash form-control"></span></td>'
                        +'</tr>');
            }
        });

ajax代码:

$.ajax({
        url : "http://localhost:8080/IDNS_Rule_Configuration/idns/systemData/getAllSites",
        type : "GET",
        contactType : "application/json",
        dataType : "json",
        success : function(data){
            for(var i=0;i<data.length;i++){
                var dataId = data[i].siteId;
                var dataArray = data[i].siteName;
                $('#siteContainer').populate(dataId, dataArray);
            }
        }
    });

填充jquery代码:

$.fn.populate = function(dataId, dataArray) {
        var $selectbox = $(this);
        // check if eleme   nt is of type select
        if ($selectbox.is("select")) {
            //for (var i = 0; i < dataId.length; i++) {
                $selectbox.append('<option value="' + dataId
                        + '" stream="' + dataId + '">'
                        + dataArray + '</option>');
            //}
        }
    };

This is my output ,site name combo box is loaded from db.In first row it works .At second row it does not work

0 个答案:

没有答案