javascript - 如何从angularjs中的国家ID获取国家名称

标签 javascript jquery html angularjs bind

大家好,很抱歉这个菜鸟问题 但我遇到了一个问题。问题是: 我正在从数据库获取国家/地区 ID,并且我想显示所选国家/地区名称 这是代码

 $scope.Customer.CU_Country = data.cU_Country;

我使用 ng-model 在 html 上获取 Id

ng-model="Customer.CU_Country"

我想根据国家/地区 idin html 显示国家/地区名称,我该怎么做? 这里的字段是

id and name

但是当我使用 html 显示国家/地区时 {{Customer.CU_Country}} 然后它显示国家/地区 ID,我如何替换名称中的 ID。

最佳答案

您可以使用 ng-model 作为

"Customer.CU_Country.name"

演示

var menuApp = angular.module("menuApp", []);
menuApp.controller("menuCtrl", function($scope) {
  $scope.Customer = {};
  $scope.Customer.CU_Country = {
    id: 101,
    name: "india"
  };
});;
<!DOCTYPE html>
<html>
<head>
  <script data-require="angular.js@1.4.7" data-semver="1.4.7" src="https://code.angularjs.org/1.4.7/angular.js"></script>
</head>
<body ng-app='menuApp'>
  <div ng-controller="menuCtrl">
    <input type="text" name="input" ng-model="Customer.CU_Country.name">
    <input type="text" name="input" ng-model="Customer.CU_Country.id">
  </div>
</body>
</html>

关于javascript - 如何从angularjs中的国家ID获取国家名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40989646/

相关文章:

javascript - 如何根据输入字段中的给定数据计算年龄?

javascript - 使用 HTML5 工具提示会在 Google Chrome 上破坏页面

html - 我想使用 CSS 在 html 中水平添加许多图像

javascript - 如何创建这个下拉框

javascript - .js 库 "Uncaught ReferenceError: numjs is not defined"

jquery - 单击选项即可显示元素

jquery - 如何使用显式变量而不是列名称

javascript - iframe 内的按钮单击功能会更改该父 iframe 的高度(跨域)

javascript - angular.js 和 zurb foundation 显示模态

javascript - TypeScript - 扩展标准库 Math 的类型定义