gpt4 book ai didi

javascript - 当将 `track by $index` 与过滤器一起使用时,我收到错误。怎么解决这个问题?

转载 作者:行者123 更新时间:2023-11-28 18:44:48 24 4
gpt4 key购买 nike

我有一个错误的字符串数组值。它里面有重复的值。我想从数组字符串中删除不需要的空格和数字。所以我用过滤器清洁所有东西。

问题是,当我单独使用过滤器时,我会收到重复错误,如果我删除它,我的过滤器将无法工作。

如何处理这种情况?

这是我的代码:

var myApp = angular.module('myApp',[]);

arr=[
"1. Completion of Site mobilization \n2. Erection of Tower cranes 2, 4 & 5\n3. Facade dismantling (Grey ACP between Gates 19, 23 & 24; Steel Louvers between Gates 2 & 3) \n4. Excavation for Foundation (AHU Corridor, Foundation Area 1, 2 &3, External Buildings)\n5. Civil Works on East Expansion for foundation (F50, F52, F55, F57, F94)\n6. West Stand Roof catwalks dismantling completed 100 %\n7. Assembly/Erection of temporary towers for Lighting Arch \n dismantling\n8. Score Board dismantling\n9. Completion of Site mobilization 10. Erection of Tower cranes 2, 4 & 5\n11. Facade dismantling (Grey ACP between Gates 19, 23 & 24; Steel Louvers between Gates 2 & 3) \n12. Excavation for Foundation (AHU Corridor, Foundation Area 1, 2 &3, External Buildings)\n13. Civil Works on East Expansion for foundation (F50, F52, F55, F57, F94)14. West Stand Roof catwalks dismantling completed 100 %\n15. Assembly/Erection of temporary towers for Lighting Arch \n dismantling\n16. Score Board dismantling",
"",
""
]


myApp.controller('main', function($scope){

$scope.arrays = arr;

});

angular.module("myApp")
.filter("string2array",

function () {

return function ( value ) {

if(!value) return;

return value.filter(Boolean).join('\n').replace(/^\d+\.\s+/gm, '').split('\n');

}

});

这是我的js尝试:Js Demo

这里是 angularjs 集成,这给我带来了问题

angualrjs demo

最佳答案

过滤器应用于数组,因此您只需要做..

<li ng-repeat="array in arrays | string2array track by $index">

fiddle

关于javascript - 当将 `track by $index` 与过滤器一起使用时,我收到错误。怎么解决这个问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35554294/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com