1

所有,我有一个表,我通过 jquery 和 ajax 填充。我正在尝试添加一个通过 ajax 数据填充的下拉菜单。这是工作表和不工作的字段。我不知道如何附加多个字段(循环通过值)。

    function loadMan(education, country)
{


// this commented out code validates that what is returned actually contains data. It does and works.
//$.each(country , function(i) { 
  //alert(country[i].country); 
//});

        //loop to fill in education data
        for (var i = 0; i < education.length; i++)
        {
                var yearComp;//value to cover dueDate zero ocurrences
                if (education[i].eduYear === null)//zero ocurrence jason changed from 0000-00-00 to null
                {
                        yearComp = '';
                }
                else
                {
                        yearComp = education[i].eduYear;
                }
                //fill in table values for education section
                $('#eduTable').find('tbody').append($('<tr>')
                .append($('<td>').append($('<input>', {'class': 'yearComp', 'name': 'eduYear', 'value': yearComp, 'readonly': 'readonly'}).datepicker(dateParams)))
//              .append($('<td>').addClass('printable').append($('<div>')).append($('<textarea>', {'name': 'eduCountry', 'text': education[i].eduCountry, 'readonly': 'readonly'}).addClass('yearComp').keydown(function(){change($(this));}).bind('paste', function(){change($(this));})))
i               // the below code does populate one value in the drop down menu. I need to loop through all the values, add them and then select the one returend by education[i].eduCountry
                .append($('<td>').append($('<select>', {'type': 'input','name': 'eduCountry'}).append(new Option(country[i].country, country[i].country_id, false, false))))
                .append($('<td>').addClass('printable').append($('<div>')).append($('<textarea>', {'name': 'eduSchool', 'text': education[i].eduSchool, 'readonly': 'readonly'}).keydown(function(){change($(this));}).bind('paste', function(){change($(this));})))
                .append($('<td>').addClass('printable').append($('<div>')).append($('<textarea>', {'name': 'eduArea', 'text': education[i].eduArea}).addClass('managerEdit').keydown(function(){change($(this));}).bind('paste', function(){change($(this));})))
                .append($('<td>').addClass('printable').append($('<div>')).append($('<textarea>', {'name': 'eduDegree', 'text': education[i].eduDegree}).addClass('managerEdit').keydown(function(){change($(this));}).bind('paste', function(){change($(this));})))
                .append($('<td align="center">').addClass('clickX').append($('<input>', {'value': 'X', 'type': 'button', 'title': 'Clicking this will delete this row', 'class': 'delButton'})
                        .click(function(){delEducationRow($(this));}))
                .append($('<input>', {'name': 'eduSql', 'value': 'read', 'type': 'hidden'}).addClass('sql'))
                .append($('<input>', {'name': 'eduId', 'value': education[i].edu_id, 'type': 'hidden'}).addClass('id'))));
        }
}
function addEducationRow()
{
    $('#eduTable').find('tbody').append($('<tr>')
        .append($('<td>').append($('<input>', {'class': 'yearComp', 'name': 'eduYear', 'readonly': 'readonly'}).datepicker(dateParams)))
        .append($('<td>').addClass('printable').append($('<div>')).append($('<textarea>', {'name': 'eduCountry'})
                .addClass('managerEdit').keydown(function(){change($(this));}).bind('paste', function(){change($(this));})))
        .append($('<td>').addClass('printable').append($('<div>')).append($('<textarea>', {'name': 'eduSchool'})
                .addClass('managerEdit').keydown(function(){change($(this));}).bind('paste', function(){change($(this));})))
        .append($('<td>').addClass('printable').append($('<div>')).append($('<textarea>', {'name': 'eduArea'})
                .addClass('managerEdit').keydown(function(){change($(this));}).bind('paste', function(){change($(this));})))
        .append($('<td>').addClass('printable').append($('<div>')).append($('<textarea>', {'name': 'eduDegree'})
                .addClass('managerEdit').keydown(function(){change($(this));}).bind('paste', function(){change($(this));})))
        .append($('<td>').addClass('clickX').css('align', 'center').addClass('delButton')
            .append($('<input>', {'value': 'X', 'type': 'button', 'title': 'Clicking this will delete this row'})
            .click(function(){delGoalRow($(this));}))
            .append($('<input>', {'name': 'eduSql', 'value': 'insert', 'type': 'hidden'}))
            .append($('<input>', {'name': 'eduId', 'value': '0', 'type': 'hidden'}).addClass('id'))));
}
4

0 回答 0