我正在研究 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/