javascript - 如何使用 Angularjs 从 json 中删除字符串中的数字?

标签 javascript angularjs json api ng-options

我正在研究 Angular。代码中的 Api 传递带有字符串的 json 值,其中包含数字和字母。但我的要求是仅显示字母并从我的下拉列表中的字符串中删除数字。

我的脚本:

staffService.getBaseBranches()
    .success(function(data) {
      $scope.baseBranches = data;

    })
    .error(function(error, status) {
      showError(error, status);
      notificationFactory.error("Unable to load base branches.");
    });

我的 html:

 <div class="form-group">
        <label>Branch : <i class="mandate">*</i></label>
           <select class="form-control input-md" name='branchName' ng-model="query.branchName" ng-options="branch.branchName as branch.branchName for branch in baseBranches">

           <option value="" selected>-- Select Branch --</option>
            </select>
                  <span class="error" ng-show="search_form.branchName.$error.required">Branch is required</span>
</div>

我该怎么做?请帮助我。

最佳答案

您可以在通过调用 showName 函数显示它时更改 branchName。 showName 将负责从 string

中删除 digits
ng-options="branch.branchName as showName(branch.branchName) for branch in baseBranches"

代码

$scope.showName = function(branchName ){
   return branchName.replace(/\d+/g, '')
}

关于javascript - 如何使用 Angularjs 从 json 中删除字符串中的数字?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40970948/

相关文章:

javascript - 如何在一个函数中实现多个ajax?

javascript - 如何以 Angular 延迟加载 Controller ?

javascript - Angular UI Bootstrap 异步预输入 : $viewValue undefined

ios - 解析YouTube JSON以获取UITableView

javascript - while 循环退出而不是返回循环 -Javascript

javascript - 如何获取超过选择输入的数据属性?

javascript - angularJS ng-repeat过滤器不适用于动态场

java - 使用 Retrofit 2,但预期为 BEGIN_OBJECT,但在第 1 行第 1 列路径 $ 处为 STRING

javascript - 为什么通过 AJAX 发送 POST 被 HTTP 服务器解释为 OPTIONS 而通过 CURL 发送实际上是 PUT?

javascript - 在 coffeescript 中调用函数定义的方法