资源模拟.js无法解析正确的 URL



我正在使用ResourceMock.js来伪造数据并返回一些自定义产品数据。当我尝试获取产品列表并点击网址/产品时,事情工作正常

但是对于特定的产品,我想传递产品ID,URL将类似于/product/edit?productId。

我正在尝试使用一些正则表达式的东西来获取该功能,但它没有按预期工作。

控制台中记录的错误是意外请求:GET/api/products?productId=4

//working fine for getting list of all products. :)
 var producturl = "/api/products";
        $httpBackend.whenGET(producturl).respond(products);
//when try to get specific item things goes wrong. :(
        var editRegex = new RegExp(producturl + "/[A-Za-z0-9]", '');
        alert(editRegex);
        $httpBackend.whenGET(editRegex).respond(function(method, url, data) {
//do some stuff and return
});
=[A-Za-z0-9]

您与=不匹配。将其包含在 prodcuturl 或正则表达式匹配中。

最新更新