mfa*_*jer 0 javascript arrays json oracle-apex
我试图写一个if语句,确定getDeptJSON数组是否包含多个值.如果是,则重定向到其他页面.通过我的研究,它似乎很简单getDept.length > 1,但我还是无法完成这项工作.
我的Javascript代码如下:
$.getJSON("https://apex.oracle.com/pls/apex/mfajertest1/department/"+$x('P2_DEPT_NO').value, function(getDept)
{
console.log(getDept);
if(getDept.length == 0)
{
window.alert("No Department with that ID");
}
else if(getDept.length > 1)
{
apex.navigation.redirect('f?p=71293:11');
}
else
{
$x('P2_DEPT_NAME').readOnly = false;
$x('P2_DEPT_NAME').value=getDept.items[0].dname;
$x('P2_DEPT_NAME').readOnly = true;
$x('P2_DEPT_LOC').readOnly = false;
$x('P2_DEPT_LOC').value=getDept.items[0].loc;
$x('P2_DEPT_LOC').readOnly = true;
$x('P2_DEPT_NO').readOnly = true;
}
});
Run Code Online (Sandbox Code Playgroud)
getDept JSON数组包含以下信息:
{
"next": {
"$ref": "https://apex.oracle.com/pls/apex/mfajertest1/department/%7Bid%7D?page=1"
},
"items": [
{
"deptno": 10,
"dname": "accounting",
"loc": "madison"
},
{
"deptno": 20,
"dname": "Finance",
"loc": "Milwaukee"
},
{
"deptno": 30,
"dname": "IT",
"loc": "La Crosse"
},
{
"deptno": 40,
"dname": "Purchasing",
"loc": "Green Bay"
},
{
"deptno": 10,
"dname": "Accounting II",
"loc": "Madison II"
},
{
"deptno": 50,
"dname": "Sports",
"loc": "Waukasha"
}
]
}
Run Code Online (Sandbox Code Playgroud)
如果需要,我很乐意提供有关此问题的更多信息.
您的JSON响应实际上是一个对象,而不是一个数组.您要检查的数组是该对象内的一个属性items.因此,无论您在哪里使用getDept,您都应该使用getDept.items:
$.getJSON("https://apex.oracle.com/pls/apex/mfajertest1/department/"+$x('P2_DEPT_NO').value, function(getDept)
{
console.log(getDept.items);
if(getDept.items.length == 0)
{
window.alert("No Department with that ID");
}
else if(getDept.items.length > 1)
{
apex.navigation.redirect('f?p=71293:11');
}
else
{
$x('P2_DEPT_NAME').readOnly = false;
$x('P2_DEPT_NAME').value=getDept.items[0].dname;
$x('P2_DEPT_NAME').readOnly = true;
$x('P2_DEPT_LOC').readOnly = false;
$x('P2_DEPT_LOC').value=getDept.items[0].loc;
$x('P2_DEPT_LOC').readOnly = true;
$x('P2_DEPT_NO').readOnly = true;
}
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
204 次 |
| 最近记录: |