简体   繁体   English

基于下拉选择的AngularJs复杂模型

[英]AngularJs complex model based on drop down selection

Not having a lot of experience with complex angular js models, i'd like to ask for your advice or help. 我对复杂的Angular js模型没有很多经验,我想请教您一些建议或帮助。 Please look at the following picture. 请看下面的图片。 It shows what I'm trying to accomplish. 它显示了我要完成的工作。 在此处输入图片说明

I need to store the number of patients for a center for each year in the drop down. 我需要在下拉列表中存储每年该中心的患者数量。 When I select another year, the input fields should be blank (or populated with data from DB). 当我选择另一年时,输入字段应为空白(或使用来自DB的数据填充)。 When I switch back to 2012, the input data should still be present. 当我切换回2012年时,输入数据仍应存在。 The data should be submitted only when the button is pressed. 仅在按下按钮时才提交数据。

I have a hard time figuring out how the model and data binding should look like. 我很难弄清模型和数据绑定的外观。 Any ideas are appreciated. 任何想法表示赞赏。

Hopefully this try may be a idea for you. 希望这次尝试对您来说是个好主意。 Please have a look for it. 请看看。

Plunker: http://plnkr.co/edit/ndRk1Uaoe0DkRhFSsGUh?p=preview 柱塞: http ://plnkr.co/edit/ndRk1Uaoe0DkRhFSsGUh?p=preview

Code: 码:

$scope.qty = 1;
$scope.cost = 2;
$scope.inCurr = 'EUR';
$scope.currencies = ['USD', 'EUR', 'CNY'];
$scope.usdRates = [
 { quantity:0,cost:0}];

 $scope.change = function() {

  if($scope.usdToForeignRates === 'USD')
  {
   $scope.usdRates[0].quantity = 25;
   $scope.usdRates[0].cost = 30;
   $scope.qty =$scope.usdRates[0].quantity;
   $scope.cost = $scope.usdRates[0].cost;
   }
       if($scope.usdToForeignRates === 'EUR')
  {
   $scope.usdRates[0].quantity = 45;
    $scope.usdRates[0].cost = 40;
   $scope.qty =$scope.usdRates[0].quantity;
   $scope.cost = $scope.usdRates[0].cost;
   }
  if($scope.usdToForeignRates === 'CNY')
  {
   $scope.usdRates[0].quantity = 55;
    $scope.usdRates[0].cost = 50;
   $scope.qty =$scope.usdRates[0].quantity;
   $scope.cost = $scope.usdRates[0].cost;
   }
  };

}]); }]);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM