ANGULAR中添加物品JSON与弹出 [英] Add item json in ANGULAR with pop-up

查看:152
本文介绍了ANGULAR中添加物品JSON与弹出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在做一个web应用程序。

我有一个动态的。首先,你选择的产品,然后在。项目在选择列表中采取JSON。现在的问题是,我想补充的可能性创造新的项目中添加<选择> LOT

所以,首先我尝试添加在很多领域使用以下codeS 列:

  $ scope.addLot =功能(ID,缬氨酸,lotId){
    //的console.log(ID);
    VAR inWhichProduct = ID;
    VAR newArray = {价值:VAL,ID:lotId};
   //console.log($scope.items)
    angular.forEach($ scope.items,功能(V,I){
      如果($ scope.items [I] .ID == ID)
      {
        $ scope.items [I] .lots.push(newArray);
        的console.log($ scope.items [I] .lots);
      }
    });
  };

和它的工作原理(这里就是一个例子)。但我想做的是在一个模式窗口移动这些领域。我想这一点,但它不工作(这里是另一个例子) 。为什么?也许正确的做法是在JSON添加项目,然后刷新的,但我怎么能在JSON添加的项目?


解决方案

\r
\r

<!DOCTYPE HTML>\r
< HTML NG-应用=应用程序NG控制器=ExampleController>\r
\r
< HEAD>\r
  <标题>&计算器LT; /标题>\r
  <间的charset =UTF-8>\r
  < META NAME =视口CONTENT =WIDTH =设备宽度,初始规模= 1>\r
  <链接HREF =htt​​ps://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css的rel =stylesheet属性/>\r
< /头>\r
\r
<身体GT;\r
\r
  < D​​IV CLASS =容器>\r
    <表类=表表镶上>\r
      < TR NG重复=中的相关信息的信息>\r
        &所述; TD>\r
          {{info.name}}\r
        < / TD>\r
        &所述; TD>\r
          <按钮式=按钮级=BTN BTN-主要BTN-SM数据切换=莫代尔数据目标=#myModalNG点击=goToModal(信息)>\r
            启动演示模式\r
          < /按钮>\r
        < / TD>\r
      < / TR>\r
    < /表>\r
  < / DIV>\r
\r
\r
  <! - 按键触发模式 - >\r
  <! - 模态 - >\r
  < D​​IV CLASS =模式变脸ID =myModal的tabindex = - 1角色=对话框中的咏叹调-labelledby =myModalLabel>\r
    < D​​IV CLASS =模式,对话框的角色=文件>\r
      < D​​IV CLASS =模式内容>\r
        < D​​IV CLASS =模头>\r
          <按钮式=按钮级=关闭数据解雇=莫代尔ARIA标签=关闭><跨度ARIA隐藏=真>&安培;倍;< / SPAN>\r
          < /按钮>\r
          < H4类=模式标题ID =myModalLabel>模态标题< / H4>\r
        < / DIV>\r
        < D​​IV CLASS =模体>\r
          {{newDataInModal.name}}\r
        < / DIV>\r
        < D​​IV CLASS =模式躯>\r
          <按钮式=按钮级=BTN BTN-默认的数据驳回=模式>关闭< /按钮>\r
          <按钮式=按钮级=BTN BTN-小学>保存更改LT; /按钮>\r
        < / DIV>\r
      < / DIV>\r
    < / DIV>\r
  < / DIV>\r
\r
  &所述; SCRIPT SRC =HTTP://$c$c.jquery.com/jquery-1.11.3.min.js>&下; /脚本>\r
  &所述; SCRIPT SRC =htt​​ps://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js>&下; /脚本>\r
  &所述; SCRIPT SRC =htt​​ps://cdnjs.cloudflare.com/ajax/libs/angular.js/1.5.0-rc.0/angular.js>&下; /脚本>\r
\r
  <脚本>\r
    angular.module('应用',[])\r
      .controller('ExampleController',['$范围',\r
        功能($范围){\r
          $ scope.infos = [{\r
            名道:我会去莫代尔\r
          }];\r
\r
          $ scope.goToModal =功能(信息){\r
            $ scope.newDataInModal =信息;\r
          }\r
        }\r
      ]);\r
  < / SCRIPT>\r
< /身体GT;\r
\r
< / HTML>

\r

\r
\r

I'm doing a web app.

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.

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);
      }
    });
  };

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?

解决方案

<!DOCTYPE html>
<html ng-app="app" ng-controller="ExampleController">

<head>
  <title>stackoverflow</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" />
</head>

<body>

  <div class="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>
  </div>


  <!-- 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>

  <script src="http://code.jquery.com/jquery-1.11.3.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.5.0-rc.0/angular.js"></script>

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

          $scope.goToModal = function(info) {
            $scope.newDataInModal = info;
          }
        }
      ]);
  </script>
</body>

</html>

这篇关于ANGULAR中添加物品JSON与弹出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆