を示す表を構築するためにJSONデータを取得するためのjQueryを使用して、私はこの未定義
{
secInfo: [
{
loginResult: 1,
userId: "admin",
userName: "admin",
userpassword: "ramshyam"
},
{
address: "",
loginResult: 1,
userEmail: "",
userId: "anuraag",
userName: "Anuraag",
userpassword: "kk0903"
}
]
}
私はテーブル内のデータを表示するためにjqueryのコードの下に使用する場合、それは "と表に移入ように見えるJSONを持っています
<script>
$(document).ready(function(){
//attach a jQuery live event to the button
$('#submitlogin').live('click', function(){
$.getJSON('/acc/services/json/security/loginresult.json', function(data) {
//alert(data); //uncomment this for debug
//alert (data.item1+" "+data.item2+" "+data.item3); //further debug
// $('#showdata').html("<p>Result="+data.loginResult+" userid="+data.userId+" username="+data.userName+"</p>");
$.each(data.secInfo, function(){
$('#usertable').append(
function(this){
return "<tr>"+
"<td>"+this.userId+"</td>"+
"<td>"+this.userName+"</td>"+
"<td>"+this.userpassword+"</td>"+
"<td>1</td>"+
"<tr>";
}
);
})
});
});
});
</script>
」未定義の私はjQueryのに新しいですし、http://forum.jquery.com/topic/jquery-create-table-from-json-dataこの記事からいくつかのアイデアを得ました。
問題は、「これは」あなたの関数コールバックでは、予約されたキーワードをthatsのかもしれません
を動作し、どのようなウェブ見ますインスペクタコンソールが出力しています。 –
javascriptオブジェクトは設計上すべての連想配列であるため、この['userId']のようにアクセスする方が簡単かもしれません。また、「this」は異なるスコープを指します。 –
'これはコンソール上でうまく書いてあり、useridで警告しています。関数内でオブジェクトを取得していない理由を知らない – antnewbee