JSON オブジェクトを反復しようとしていますが、反復できません。
cs:
[WebMethod]
public static List<TicVersion> GetTicVersionList()
{
List<TicVersion> versionList = new List<TicVersion>
{
new TicVersion
{
Date = DateTime.Now,
Version = "2"
},
new TicVersion
{
Date = DateTime.Now,
Version = "4"
},
new TicVersion
{
Date = DateTime.Now,
Version = "13"
},
new TicVersion
{
Date = DateTime.Now,
Version = "28"
},
};
return versionList;
}
public class TicVersion
{
public DateTime Date { get; set; }
public string Version { get; set; }
}
スクリプトマネージャー
<asp:ScriptManager ID="ScriptManager1" EnablePageMethods="true" EnablePartialRendering="true"
runat="server" />
js:
$.ajax({
type: "POST",
url: "ManagerTic.aspx/GetTicVersionList",
contentType: "application/json; charset=utf-8",
dataType: "json",
async: false, // TODO!
success: function (result) {
createTicVersionList(result);
}
});
function createTicVersionList(result) {
var items = [];
$.each(result.d, function (key, val) { // here is the problem.... i am not being able to get the values
items.push('<li id="' + val.Version + '" class="ui-widget-content">' + val.Date + '</li>'); // i need the actual Date and Version
});
$('<ol/>', {
'id': 'selectable',
'class': 'ui-selectable',
html: items.join('')
}).appendTo('.baseVersion');
}
編集
> if i console.log(result) inside the each, i am getting
> - Object
> - - d
> - - - [0]
> - - - [1]
> - - - [2]
> - - - [3]