Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

我这段代码为什么输出结果是从6开始的??

Mock.mock('/test', {/*地址任意*/
    'result|5': [{
        'id|+1': 1,
        'email': '@email',
        'name':'@first'
    }]
});

$.ajax({
    url: '/test',
    dataType: 'json',
    success: function(data, status, jqXHR) {
        var content = "";
        if(data !=null){
            for(i=0;i<data.result.length;i++){
                content +='<li><span>'+data.result[i].id+'、'+data.result[i].name+'的邮箱是:'+data.result[i].email+'</span></li>';
            }
            $(".demo").html(content);
        }
    }
});

clipboard.png

clipboard.png


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
216 views
Welcome To Ask or Share your Answers For Others

1 Answer

我在官网上测试没有问题的呀:

JSON.stringify(Mock.mock( {/*地址任意*/
    'result|5': [{
        'id|+1': 1,
        'email': '@email',
        'name':'@first'
    }]
}),0,4)
"{
    "result": [
        {
            "id": 1,
            "email": "[email protected]",
            "name": "Ruth"
        },
        {
            "id": 2,
            "email": "[email protected]",
            "name": "David"
        },
        {
            "id": 3,
            "email": "[email protected]",
            "name": "Jessica"
        },
        {
            "id": 4,
            "email": "[email protected]",
            "name": "Mark"
        },
        {
            "id": 5,
            "email": "[email protected]",
            "name": "Mary"
        }
    ]
}"

换成最新的mockjs文件再试试吧


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...