Here are試圖將meter值轉換爲yard值。我有兩個下拉菜單。第一個下拉列表有一些值。第二個下拉列表有兩個值「米」&「院子」,現在的問題是如果從第二個下拉列表中選擇米,第一個下拉列表中的值要保持相同。但是,如果選擇「Yard」,則需要將第一個下拉列表中的整個值轉換爲Yard值。我發現了邏輯,但我不知道如何將其實施到角度控制器。我在這裏創建了一個plunkr https://plnkr.co/edit/Q4lxXf6YRrdAV2kUNAln?p=preview如何將yard值轉換爲angularjs中的meter值
HTML
<!DOCTYPE html>
<html>
<head>
<script data-require="[email protected]" data-semver="1.6.2" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.2/angular.js"></script>
<link rel="stylesheet" href="style.css" />
<script src="script.js"></script>
</head>
<body>
<div ng-app="app" ng-controller="ctrl">
<select class="form-control" ng-model="distancetypeId" ng-options="Distance.id as Distance.value for Distance in data"></select>
<select class="form-control" ng-model="ConverttypeId" ng-options="Convert.id as Convert.type for Convert in convertor" ng-change="convertToMeter()"></select>
</div>
</body>
</html>
AngularJS
angular.module("app",[])
.controller("ctrl",function($scope){
$scope.data = [{
"id": 1,
"value": 254
},
{
"id": 2,
"value": 100
},
{
"id": 3,
"value":250
},
{
"id": 4,
"value":10
}]
$scope.convertor = [{
"id": 1,
"type": "Meter"
},
{
"id": 2,
"type": "Yard"
}];
$scope.convertToMeter=function(ConverttypeId){
if(ConverttypeId = 2){
//this is logic that i want to do (dropdown1values=value*1.0936;)
}}
});
謝謝你讓..其做工精細.. – ManojKanth