【发布时间】:2018-11-28 18:43:18
【问题描述】:
我正在使用 AngularJs、html 来显示表格并显示表格中的记录。
演示:http://plnkr.co/edit/xHRLAynOpUiLWbOKhqUm?p=preview&preview
我正在尝试单击第二列中的数字超链接。目前,我正在使用逗号 (,) 分隔符拆分数字,并使用 <a href> 链接传递我点击的相关数字(可以查看第一行链接的工作)。
有时由于数据是动态的,我可能会得到分号 (;) 或冒号 (:) 作为分隔符,然后代码中断,在单击链接时传递多个关联的数字。
<a ng-repeat="associateNum in player.associatedNumber .split(',')" href="https://urladdr/associateid={{associateNum}}" target="_blank">
{{associateNum}}<span ng-if="$index+1 != player.associatedNumber.split(',').length">;</span></a>
即使同一行中的关联数字以,或;或:作为分隔符,如何支持上述<a href>链接?
js代码:
app.controller('MainCtrl', function($scope) {
$scope.players = [{
"name": "Robert C",
"associatedNumber": "21,10,133",
"standing": true,
"result":"Delivered,shipped,shipped"
}, {
"name": "Joey C",
"associatedNumber": "55,2:22;33",
"standing": false,
"result":"To be delivered,Delivered"
}, {
"name": "Bobby A",
"associatedNumber": "15;22:11",
"standing": true,
"result":"TO be delivered"
}, {
"name": "John A",
"associatedNumber": "1,33,34",
"standing": true,
"result":"To be delivered,shipped"
}];
});
【问题讨论】:
-
你能试试
encodeURIComponent(value)吗? -
不需要使用encodeURIComponent..我需要在点击数字时传递关联的数字。例如,对于第二行,当用户将鼠标悬停在 15 上并单击它时,我有 15;22:11,15 必须传入 URL。单击 22 时,22 应该传入 URL。但是当我使用 split(',') 时,它不会拆分值 15;22:11。所以我想使用分隔符分割,或者;或:
标签: angularjs angularjs-ng-repeat tml