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

问题描述 投票:0回答:1

我的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" />

在我的控制器中,我试图将其推入像这样的对象数组中。

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

当我做这个其他用途的控制台日志。这就是我得到的

[...] 0:{...} gfa:40使用:“\ n动态手术中心\ n \ n \ n”proto:对象{...}长度:1个原型:数组[]

我无法弄清楚为什么这些新的线条字符会被追加。当我在我的视图中显示它时,这会导致问题,所以我想摆脱它们。

提前致谢 :-) :-)

javascript arrays angularjs json object
1个回答
1
投票

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

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

$scope.info.otherUse.replace(/\n/g, '')
© www.soinside.com 2019 - 2024. All rights reserved.