使用弹出窗口在 ANGULAR 中添加项目 json

Add item json in ANGULAR with pop-up(使用弹出窗口在 ANGULAR 中添加项目 json)
本文介绍了使用弹出窗口在 ANGULAR 中添加项目 json的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在做一个网络应用程序.

I'm doing a web app.

我有一个动态的表格.首先,您选择 PRODUCT,然后选择 LOT.选择中的项目列表由 json 获取.现在的问题是我想添加创建新项目以添加到 <select> LOT 的可能性.

I have a dynamic table. First, you choose a PRODUCT and then the LOT. The list of item in the select are taken by json. Now the problem is that I want to add the possibility to create new item to add in the <select> LOT.

所以,首先我尝试使用以下代码在 LOT 列中添加该字段:

So, first I tried to add the field in the LOT column using the following codes:

  $scope.addLot = function(id,val,lotId) { 
    // console.log(id);
    var inWhichProduct = id;
    var newArray = { "value": val, "id": lotId };
   //console.log($scope.items)
    angular.forEach($scope.items,function(v,i){
      if($scope.items[i].id == id )
      {
        $scope.items[i].lots.push(newArray);
        console.log($scope.items[i].lots);
      }
    });
  };

它有效(这里是一个例子).但我想要做的是在模式窗口中移动这些字段.我试过这个,但它不起作用(这里是另一个例子).为什么?也许正确的方法是在json中添加item,然后刷新LOT,但是如何在json中添加item呢?

and it works (here is an example). But what I want to do is move those fields in a modal window. I tried this, but it doesn't work (here is another example). Why? Maybe the correct way is to add the item in the json and then refresh the LOT, but how can I add the item in the json?

推荐答案

angular.module('app', []).controller('ExampleController', ['$scope',
        function($scope) {
          $scope.infos = [
            {name: "i will go to modal 1"},
            {name: "i will go to modal 2"}
          ];

          $scope.goToModal = function(info) {
            $scope.newDataInModal = info;
          }
        }
      ]);

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" />

  <div class="container" ng-app="app" ng-controller="ExampleController">
  <!-- start container -->
  
    <table class="table table-bordered">
      <tr ng-repeat="info in infos">
        <td>
          {{info.name}}
        </td>
        <td>
          <button type="button" class="btn btn-primary btn-sm" data-toggle="modal" data-target="#myModal" ng-click="goToModal(info)">
            Launch demo modal
          </button>
        </td>
      </tr>
    </table>



  <!-- Button trigger modal -->
  <!-- Modal -->
  <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog" role="document">
      <div class="modal-content">
        <div class="modal-header">
          <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span>
          </button>
          <h4 class="modal-title" id="myModalLabel">Modal title</h4>
        </div>
        <div class="modal-body">
          {{newDataInModal.name}}
        </div>
        <div class="modal-footer">
          <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
          <button type="button" class="btn btn-primary">Save changes</button>
        </div>
      </div>
    </div>
  </div>
  
<!-- close container -->
</div>

这篇关于使用弹出窗口在 ANGULAR 中添加项目 json的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Update another component when Formik form changes(当Formik表单更改时更新另一个组件)
Formik validation isSubmitting / isValidating not getting set to true(Formik验证正在提交/isValiating未设置为True)
React Validation Max Range Using Formik(使用Formik的Reaction验证最大范围)
Validation using Yup to check string or number length(使用YUP检查字符串或数字长度的验证)
Updating initialValues prop on Formik Form does not update input value(更新Formik表单上的初始值属性不会更新输入值)
password validation with yup and formik(使用YUP和Formick进行密码验证)