小编mfa*_*jer的帖子

验证JSON数组长度

我试图写一个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": …
Run Code Online (Sandbox Code Playgroud)

javascript arrays json oracle-apex

0
推荐指数
1
解决办法
204
查看次数

标签 统计

arrays ×1

javascript ×1

json ×1

oracle-apex ×1