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

时间:2018-02-28 14:07:29

标签: javascript arrays angularjs json object

我的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   使用:&#34; \ n动态手术中心\ n \ n \ n&#34;    proto :对象{...}   长度:1    proto :Array []

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

提前致谢:-): - )

1 个答案:

答案 0 :(得分:1)

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

的内容

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

$scope.info.otherUse.replace(/\n/g, '')
相关问题