开发者

Problem appending options to a select from a JSON object

开发者 https://www.devze.com 2023-03-15 20:48 出处:网络
I have this Json from a $.getJson function: [ {\"UserName\":\"Z1\",\"FullName\":\"XY1\"}, {\"UserName\":\"Z2\",\"FullName\":\"XY2\"},

I have this Json from a $.getJson function:

[
    {"UserName":"Z1","FullName":"XY1"},
    {"UserName":"Z2","FullName":"XY2"},
    {"UserName":"Z3","FullName":"XY3"}
]

I try to append these into options of a select tag as a pair of value end text. I've tried this:

$.each(data, function(i,item) {
  alert(item.UserName + " " + item.FullName);
});

but it gave me: undefined undefined.

开发者_开发技巧

I think it should work. What's wrong?


Seems to be working fine here: http://jsfiddle.net/maniator/ZKBYU/

0

精彩评论

暂无评论...
验证码 换一张
取 消