Добавить строку в область и присвоить ей значение - PullRequest
0 голосов
/ 06 мая 2019

Как добавить строку в область, а затем присвоить ей значение в angularjs, а затем отобразить область в html5?

Пример: HTML TAG:

<table>
   <tr>
      <td>Transitoria:</td>
      <td>
         <input type="text" ng-model="formData.transitoryAccount"
                ng-keydown="$event.keyCode === 13 && searchGLAccount(formData.transitoryAccount , 'transitoryAccount')">
      </td>
      <td>{{transitoryAccount.label}}</td>
   </tr>
   <tr>
      <td>Error Account:</td>
      <td>
         <input type="text" ng-model="formData.errorAccount"
                ng-keydown="$event.keyCode === 13 && searchGLAccount(formData.errorAccount, 'errorAccount')">
      </td>
      <td>{{errorAccount.label}}</td>
   </tr>
   <tr>
      <td>End of Year Profit:</td>
      <td>
         <input type="text" ng-model="formData.EOYProfitAccount"
                ng-keydown="$event.keyCode === 13 && searchGLAccount(formData.EOYProfitAccount, 'EOYProfitAccount')">
      </td>
      <td>{{EOYProfitAccount.label}}</td>
   </tr>
</table>

В контроллере

scope.searchGLAccount = function(srchText, modelName) {
    resourceFactory.runReportsResource.get({
        reportSource: 'getAccountByAccountNo',
        R_accountNo: srchText,
        genericResultSet: false
    }, function (data) {
        scope.glAccount = data[0];
        scope.modelName['.label'] = scope.glAccount.entityName;
        scope.formData.modelName = scope.glAccount.entityAccountNo;
    });
};

Любая помощь высоко ценится .. Спасибо

Ответы [ 3 ]

0 голосов
/ 07 мая 2019

Поскольку директива ng-keydown вызывает функцию searchGLAccount со строкой для параметра modelName, в коде необходимо использовать для доступа к этому параметру скобочное обозначение :

scope.searchGLAccount = function(srchText, modelName) {
    resourceFactory.runReportsResource.get({
        reportSource: 'getAccountByAccountNo',
        R_accountNo: srchText,
        genericResultSet: false
    }, function (data) {
        scope.glAccount = data[0];
        ̶s̶c̶o̶p̶e̶.̶m̶o̶d̶e̶l̶N̶a̶m̶e̶[̶'̶.̶l̶a̶b̶e̶l̶'̶]̶ ̶=̶ ̶s̶c̶o̶p̶e̶.̶g̶l̶A̶c̶c̶o̶u̶n̶t̶.̶e̶n̶t̶i̶t̶y̶N̶a̶m̶e̶;̶ 
        scope[modelName].label = scope.glAccount.entityName;
        ̶s̶c̶o̶p̶e̶.̶f̶o̶r̶m̶D̶a̶t̶a̶.̶m̶o̶d̶e̶l̶N̶a̶m̶e̶ ̶=̶ ̶s̶c̶o̶p̶e̶.̶g̶l̶A̶c̶c̶o̶u̶n̶t̶.̶e̶n̶t̶i̶t̶y̶A̶c̶c̶o̶u̶n̶t̶N̶o̶;̶
        scope.formData[modelName] = scope.glAccount.entityAccountNo;
    });
};
0 голосов
/ 09 мая 2019

Используется [] Скобки для создания нового динамического ключа modelName to scope, перед добавлением ключа метки, определяющего его как объект и его работу. Пожалуйста, проверьте функцию

<!DOCTYPE html>
<html>

  <head>
    <meta charset="utf-8" />
    <title>AngularJS Plunker</title>
   <script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.7.5/angular.min.js"></script>
   
    <script>
    var app = angular.module('test', []);
    
    app.controller('mine',function($scope){
     
    $scope.searchGLAccount = function(srchText, modelName) {
          $scope[modelName]={};
          $scope.formData={};
          $scope[modelName]["label"]="test"; //added sample value as dont have this data $scope.glAccount.entityName
          $scope.formData[modelName] = "test1"//$scope.glAccount.entityAccountNo
          console.log($scope.transitoryAccount.label,             $scope.formData.transitoryAccount)
   /* resourceFactory.runReportsResource.get({
        reportSource: 'getAccountByAccountNo',
        R_accountNo: srchText,
        genericResultSet: false
    }, function (data) {
        $scope.glAccount = data[0];
        $scope.modelName['.label'] = $scope.glAccount.entityName;
        $scope.formData.modelName = $scope.glAccount.entityAccountNo;
    });*/
};
});
    
    </script>
  </head>

  <body ng-app="test">
    <table ng-controller="mine">
   <tr>
      <td>Transitoria:</td>
      <td>
         <input type="text" ng-model="formData.transitoryAccount" ng-keydown="$event.keyCode === 13 && searchGLAccount(formData.transitoryAccount , 'transitoryAccount')">
      </td>
      <td>{{transitoryAccount.label}}</td>
   </tr>
   <tr>
      <td>Error Account:</td>
      <td>
         <input type="text" ng-model="formData.errorAccount" ng-keydown="$event.keyCode === 13 && searchGLAccount(formData.errorAccount, 'errorAccount')">
      </td>
      <td>{{errorAccount.label}}</td>
   </tr>
   <tr>
      <td>End of Year Profit:</td>
      <td>
         <input type="text" ng-model="formData.EOYProfitAccount" ng-keydown="$event.keyCode === 13 && searchGLAccount(formData.EOYProfitAccount, 'EOYProfitAccount')">
      </td>
      <td>{{EOYProfitAccount.label}}</td>
   </tr>
</table>
    
  </body>

</html>
0 голосов
/ 06 мая 2019

<!DOCTYPE html>
<html>

  <head>
    <meta charset="utf-8" />
    <title>AngularJS Plunker</title>
   <script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.7.5/angular.min.js"></script>
   
    <script>
    var app = angular.module('test', []);
    
    app.controller('mine',function($scope){
     $scope.transitoryAccount= {label:"Transitoria - Label"};
     $scope.errorAccount= {label:"Transitoria - Label"};
     $scope.EOYProfitAccount= {label:"Transitoria - Label"};
    });
    
    </script>
  </head>

  <body ng-app="test">
    <table ng-controller="mine">
   <tr>
      <td>Transitoria:</td>
      <td>
         <input type="text" ng-model="formData.transitoryAccount" ng-keydown="$event.keyCode === 13 && searchGLAccount(formData.transitoryAccount , 'transitoryAccount')">
      </td>
      <td>{{transitoryAccount.label}}</td>
   </tr>
   <tr>
      <td>Error Account:</td>
      <td>
         <input type="text" ng-model="formData.errorAccount" ng-keydown="$event.keyCode === 13 && searchGLAccount(formData.errorAccount, 'errorAccount')">
      </td>
      <td>{{errorAccount.label}}</td>
   </tr>
   <tr>
      <td>End of Year Profit:</td>
      <td>
         <input type="text" ng-model="formData.EOYProfitAccount" ng-keydown="$event.keyCode === 13 && searchGLAccount(formData.EOYProfitAccount, 'EOYProfitAccount')">
      </td>
      <td>{{EOYProfitAccount.label}}</td>
   </tr>
</table>
    
  </body>

</html>
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...