我在使用JSON列表填充下拉列表时遇到问题。 这是我在我的功能中所做的。
onPhaseChange1: function(dropdown, row) {
var combobox = $(dropdown);
comboboxWorkUnit = row.find("select.workUnit");
EmployeeType = $("input[id*='EmployeeType']").val();
comboboxWorkUnit.show();
comboboxWorkUnit.empty();
var jsonList = {
[{ "Id": "12345", "WorkUnitId": "SR0001954", "Description": "Test Service Request From Serena", "WorkUnitCategory": "ServiceRequest" },
{ "Id": "12355", "WorkUnitId": "WOR001854", "Description": "Test Work Order From Serena", "WorkUnitCategory": "ServiceRequest" },
{ "Id": "12365", "WorkUnitId": "DBR001274", "Description": "Test Database Related Service Request From Serena", "WorkUnitCategory": "ServiceRequest"}]}
$($.parseJSON(jsonList)).map(function() { $('<option>').val(this.Id).text(this.Id).appendTo(comboboxWorkUnit); });
},
答案 0 :(得分:1)
你的jsonList应该只是一个数组。它不需要在一个对象中。然后调用阵列上的每个。小提琴:http://jsfiddle.net/brentmn/Jkxe2/
var comboboxWorkUnit = $("select.workUnit");
comboboxWorkUnit.show();
comboboxWorkUnit.empty();
var jsonList = [{
"Id": "12345",
"WorkUnitId": "SR0001954",
"Description": "Test Service Request From Serena",
"WorkUnitCategory": "ServiceRequest"},
{
"Id": "12355",
"WorkUnitId": "WOR001854",
"Description": "Test Work Order From Serena",
"WorkUnitCategory": "ServiceRequest"},
{
"Id": "12365",
"WorkUnitId": "DBR001274",
"Description": "Test Database Related Service Request From Serena",
"WorkUnitCategory": "ServiceRequest"}];
$(jsonList).each(function() {
comboboxWorkUnit.append($('<option>').val(this.Id).text(this.Id));
});