我想訪問單選按鈕(性別字段)中的jsongrid值,而不應用html.I嘗試了簡單的JavaScript函數,它在UI中正常工作,但通過html輸入來值但我希望值來從jsongrid.Plz幫我..如何通過javascript訪問JSON數據
這是JavaScript代碼
<script type="text/javascript">
$j.ajax({
url:"UserGender",
type: "GET",
data: datasourses,
dataType: "json",
success: function (data){
$.each(data, function(i, selectedItem) {
alert("paramValue: " + selectedItem.paramValue + ", paramCode: " +
data.selectedItem.paramCode);
});
}
});
</script>
這是HTML
<input type="radio" name="Female" >
<input type="radio" name="Male" >
的Json代碼
{
"jsonWrapperforGrid": {
"page": "1",
"total": "2",
"rows": [
{
"tenantId": 0,
"paramType": "UserGender",
"paramCode": "F",
"langCode": "en",
"paramValue": "Female"
},
{
"tenantId": 0,
"paramType": "UserGender",
"paramCode": "M",
"langCode": "en",
"paramValue": "Male",
"paramBlob": ""
}
]
}
}
在此先感謝
請你能告訴什麼'每()'應打印?預期產出是多少? – fcalderan 2012-08-02 12:50:15
'data'將是隻包含一個屬性'jsonWrapperforGrid'的對象。如果你想訪問'rows'中的數組,它將是'data.jsonWrapperforGrid.rows'。這是JavaScript 101,請閱讀https://developer.mozilla.org/en/JavaScript/Guide/Working_with_Objects – 2012-08-02 12:51:04