gpt4 book ai didi

javascript - 将对象推送到数组时,新行会附加在末尾

转载 作者:行者123 更新时间:2023-12-03 02:24:01 25 4
gpt4 key购买 nike

我的 html 中有一个选择输入和输入

   <select class="span3 align-right-input" ui-select2="{minimumResultsForSearch: -1}" ng-model="info.otherUse" ng-init="info.otherUse=lists.primaryFunctions[0].typeName">
<option ng-repeat="list in lists.primaryFunctions">
{{list.typeName}}
</<option>

</select>

<input type="number" name="otherGfa" ng-model="info.otherGfa" />

在我的 Controller 中,我试图将其插入这样的对象数组中。

 $scope.otheruses.push({'use':$scope.info.otherUse,'gfa':$scope.info.otherGfa});

当我对其他用途进行控制台日志时。这就是我得到的

[…] 0: {…} gfa: 40 use: "\n Ambulatory Surgical Center\n \n\n " proto: Object { … } length: 1 proto: Array []

我无法弄清楚为什么要附加这些新行字符\n 。当我在 View 中显示它时,这会导致问题,所以我想删除它们。

提前致谢:-) :-)

最佳答案

不知道为什么 \n 首先存在,很可能它已经存在于您引用的源字段中。您应该检查 $scope.info.otherUse 的内容。

至于摆脱它,这里有一个正则表达式:

$scope.info.otherUse.replace(/\n/g, '')

关于javascript - 将对象推送到数组时,新行会附加在末尾,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49031451/

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