ResultDataはCommandModelオブジェクトのリストです。ajax成功呼び出しはオブジェクトのjsonリストを返します - アクセス不可プロパティ
[ { "Command": "Blueprint", "Count": 77 }, { "Command": "Template", "Count": 188 }, { "Command": "Test", "Count": 78 } ]
が返されるのオブジェクトは次のようになり、
public class CommandModel
{
public string Command {get; set;}
public int Count {get; set;}
}
このビデオ(https://www.youtube.com/watch?v=7oUZXuI7OgQ)で説明したように、私は、ドットプロパティ表記を使用してオブジェクトのデータにアクセスしようとしています。実行時、最初の反復で
$("#btn").click(function() {
$.ajax({
url: "http://localhost:6023/external",
type: "GET",
accept: "application/json",
dataType: 'json',
success: function (resultData) {
$.each(resultData, function (key, value) {
var command = value.command; // returns undefined
var count = value.count; // returns undefined
$("tbl").append("<tr><td>" + command + "</td><td>" + count + "</td></tr>")
})
},
error: function (e) {
alert("something broke");
}
})
、変数は次のようになります。
Key = 0
Value = Object {Command:"Blueprint", Count:77}
ない私がここで行方不明です何を確認してください。
JavaScriptは大文字と小文字を区別しています。 'var command = value.Command;'などを試してください。 –
@KelvinSherlock Doh、それでした。データは正しく引き出されていますが、テーブルに正しく格納されていません。それが別のものでなければ:)答えとして提出すること自由に感じ、私は喜んで受け入れるだろう。 –