Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/465.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 正斜杠在AngularJS中被替换为:%252F_Javascript_Regex_Angularjs - Fatal编程技术网

Javascript 正斜杠在AngularJS中被替换为:%252F

Javascript 正斜杠在AngularJS中被替换为:%252F,javascript,regex,angularjs,Javascript,Regex,Angularjs,我已经编写了一个AngularJS应用程序,其中输入框中的值的更改将动态更新到URI中,该URI被前斜杠分割,作为在URI中存储数据的一种方法,最终可以共享。基本上,URL就是数据库。当有人访问URI时,URI字符串中的值将重新插入应用程序的范围。示例设置页面: 将输入框中的值放入URI时,我使用以下函数: $scope.go = function (term,pos) { /* Fires on Keyup, pushes term into the path */

我已经编写了一个AngularJS应用程序,其中输入框中的值的更改将动态更新到URI中,该URI被前斜杠分割,作为在URI中存储数据的一种方法,最终可以共享。基本上,URL就是数据库。当有人访问URI时,URI字符串中的值将重新插入应用程序的范围。示例设置页面:

将输入框中的值放入URI时,我使用以下函数:

    $scope.go = function (term,pos) { /* Fires on Keyup, pushes term into the path */
        // var res = term.replace(/\//g, "%2F"); Fix to allow slash in fields
        $location.path(update(decodeURI($location.url()),pos,term), false);
    };


function update(line,index,term) {
    var arr = line.split("/");
    arr.splice(index,1,term);
    var res = arr.join("/");
    return res;
}
当从URL获取值进入范围时,我使用decodeURI,例如:

$scope.TeamAN = decodeURI(arr[14]);
我的问题是前斜杠。e、 g.如果我输入N/A,当输入交叉进入下一个字段时,会导致一个重大问题

理想情况下,我会用%2F替换所有正向斜杠,但当我这样做时,请使用:

term.replace(/\//g, "%2F")
以下内容已更新为URI:

N%252FA-它被双重编码

刷新页面时,将返回:

N%2FA

而不是我所期望的不适用

希望这是明确的。协助解决此问题将不胜感激


关于,

根据讨论,首先将
/
更改为
%2F

$scope.go = function (term,pos) { /* Fires on Keyup, pushes term into the path */
    var res = term.replace(/\//g, "%2F"); Fix to allow slash in fields
    $location.path(update(decodeURI($location.url()),pos,res), false);
};
然后,在读取URI时,需要解码
%2F

旧代码
//用URL中找到的任何值填充框
var url=$location.url();
var arr=url.split(“/”);
$scope.LeagueDivision=decodeURI(arr[3]);
$scope.vention=decodeURI(arr[4]);
$scope.Competition=decodeURI(arr[5]);
$scope.PhaseMatch=decodeURI(arr[6]);
$scope.question=decodeURI(arr[7]);
$scope.Scorer=decodeURI(arr[8]);
$scope.TeamAN=decodeURI(arr[9]);
$scope.TeamBN=解码URI(arr[10]);
$scope.Player=[];
对于(var i=0;i<8;i++){$scope.Player[i]=decodeURI(arr[i+11]);}
$scope.TeamAS=parseInt(0+decodeURI(arr[19]);
$scope.TeamBS=parseInt(0+decodeURI(arr[20]);
$scope.Start=[];
对于(vari=0;i<8;i++){$scope.Start[i]=decodeURI(arr[i+21]);}
$scope.First=parseInt(0+decodeURI(arr[29]);
$scope.StartDateTime=decodeURI(arr[30]);
$scope.TeamAC=parseInt(0+decodeURI(arr[31]);
$scope.TeamBC=parseInt(0+decodeURI(arr[32]);
如果($scope.StartDateTime=''){
d=新日期();
变量日期=d.yyyymmddhhmmssmm();
$scope.StartDateTime=date.substring(0,date.length-7);
$location.path(更新(decodeURI($location.url()),30$scope.StartDateTime),false);
}
$scope.go=函数(term,pos){/*在Keyup上激发,将term推入路径*/
term=term.replace(//\//g,“%2F”);//修复允许在字段中使用斜杠
var i=update(decodeURI($location.url()),pos,term);
$location.path(i,false);
};
$scope.start=函数(){
$location.path(更新(decodeURI($location.url()),2,'TQM'),true);
如果(!$scope.$$phase){$scope.$apply();}
};
新代码
//用URL中找到的任何值填充框
var url=$location.url();
var arr=url.split(“/”);
arr=arr.map(函数(comp){返回decodeURI(comp).replace(/%2F/g,“/”)});
$scope.LeagueDivision=arr[3];
$scope.vention=arr[4];
$scope.Competition=arr[5];
$scope.PhaseMatch=arr[6];
$scope.Questioner=arr[7];
$scope.Scorer=arr[8];
$scope.TeamAN=arr[9];
scope.TeamBN美元=arr[10];
$scope.Player=[];
对于(var i=0;i<8;i++){$scope.Player[i]=arr[i+11];}
$scope.TeamAS=parseInt(0+arr[19]);
$scope.TeamBS=parseInt(0+arr[20]);
$scope.Start=[];
对于(var i=0;i<8;i++){$scope.Start[i]=arr[i+21];}
$scope.First=parseInt(0+arr[29]);
$scope.StartDateTime=arr[30];
$scope.TeamAC=parseInt(0+arr[31]);
$scope.TeamBC=parseInt(0+arr[32]);
如果($scope.StartDateTime=''){
d=新日期();
变量日期=d.yyyymmddhhmmssmm();
$scope.StartDateTime=date.substring(0,date.length-7);
$location.path(更新(decodeURI($location.url()),30$scope.StartDateTime),false);
}
$scope.go=函数(term,pos){/*在Keyup上激发,将term推入路径*/
term=term.replace(//\//g,“%2F”);//修复允许在字段中使用斜杠
var i=update(decodeURI($location.url()),pos,term);
$location.path(i,false);
};
$scope.start=函数(){
$location.path(更新(decodeURI($location.url()),2,'TQM'),true);
如果(!$scope.$$phase){$scope.$apply();}
};

您真的在使用
术语。替换(///g,“%2F”)
?不是
术语。替换(//\//g,“%2F”)
?我现在不使用这两个术语。我尝试了你提到的第二个,它是我粘贴到框中的内容,但我刚刚注意到它已更改为该内容。你能显示更新结果插入URL的位置吗?如果你单击初始超链接并开始键入(例如)联赛和分区输入框,你会看到它更新URI。这是来自控制器中的$scope.go。我已经更新了原始帖子,将$scope.go包括在内,并修复正则表达式的呈现。非常感谢您提供此解决方案。我已经更新了文件并上传了。我试图自己解决这一问题,结果省去了很多麻烦。
    // Fill the boxes with any values found in the URL
    var url = $location.url();
    var arr = url.split("/");
    $scope.LeagueDivision = decodeURI(arr[3]);
    $scope.Venue = decodeURI(arr[4]);
    $scope.Competition = decodeURI(arr[5]);
    $scope.PhaseMatch = decodeURI(arr[6]);
    $scope.Questioner = decodeURI(arr[7]);
    $scope.Scorer = decodeURI(arr[8]);
    $scope.TeamAN = decodeURI(arr[9]);
    $scope.TeamBN = decodeURI(arr[10]);
    $scope.Player = [];
    for (var i = 0; i < 8; i++) { $scope.Player[i] = decodeURI(arr[i+11]); }
    $scope.TeamAS = parseInt(0+decodeURI(arr[19]));
    $scope.TeamBS = parseInt(0+decodeURI(arr[20]));
    $scope.Start = [];
    for (var i = 0; i < 8; i++) { $scope.Start[i] = decodeURI(arr[i+21]); }
    $scope.First = parseInt(0+decodeURI(arr[29]));
    $scope.StartDateTime = decodeURI(arr[30]);
    $scope.TeamAC = parseInt(0+decodeURI(arr[31]));
    $scope.TeamBC = parseInt(0+decodeURI(arr[32]));
    if($scope.StartDateTime==''){
            d = new Date();
            var date = d.YYYYMMDDhhmmssmmm();
            $scope.StartDateTime = date.substring(0, date.length - 7);
            $location.path(update(decodeURI($location.url()),30,$scope.StartDateTime), false);
    }
    $scope.go = function (term,pos) { /* Fires on Keyup, pushes term into the path */
            term = term.replace(/\//g, "%2F"); // Fix to allow slash in fields
            var i = update(decodeURI($location.url()),pos,term);
            $location.path(i, false);
    };
    $scope.start = function () {
            $location.path(update(decodeURI($location.url()),2,'TQM'), true);
            if(!$scope.$$phase) { $scope.$apply(); }
    };
    // Fill the boxes with any values found in the URL
    var url = $location.url();
    var arr = url.split("/");
    arr = arr.map(function(comp){return decodeURI(comp).replace(/%2F/g,"/")});
    $scope.LeagueDivision = arr[3];
    $scope.Venue = arr[4];
    $scope.Competition = arr[5];
    $scope.PhaseMatch = arr[6];
    $scope.Questioner = arr[7];
    $scope.Scorer = arr[8];
    $scope.TeamAN = arr[9];
    $scope.TeamBN = arr[10];
    $scope.Player = [];
    for (var i = 0; i < 8; i++) { $scope.Player[i] = arr[i+11]; }
    $scope.TeamAS = parseInt(0+arr[19]);
    $scope.TeamBS = parseInt(0+arr[20]);
    $scope.Start = [];
    for (var i = 0; i < 8; i++) { $scope.Start[i] = arr[i+21]; }
    $scope.First = parseInt(0+arr[29]);
    $scope.StartDateTime = arr[30];
    $scope.TeamAC = parseInt(0+arr[31]);
    $scope.TeamBC = parseInt(0+arr[32]);
    if($scope.StartDateTime==''){
            d = new Date();
            var date = d.YYYYMMDDhhmmssmmm();
            $scope.StartDateTime = date.substring(0, date.length - 7);
            $location.path(update(decodeURI($location.url()),30,$scope.StartDateTime), false);
    }
    $scope.go = function (term,pos) { /* Fires on Keyup, pushes term into the path */
            term = term.replace(/\//g, "%2F"); // Fix to allow slash in fields
            var i = update(decodeURI($location.url()),pos,term);
            $location.path(i, false);
    };
    $scope.start = function () {
            $location.path(update(decodeURI($location.url()),2,'TQM'), true);
            if(!$scope.$$phase) { $scope.$apply(); }
    };