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

Categories

0 votes
224 views
in Technique[技术] by (71.8m points)

mock.js的一个问题?

我这段代码为什么输出结果是从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


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

1 Answer

0 votes
by (71.8m points)

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

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文件再试试吧


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...