如何使用AngulaJS将数据从主窗口传递到子窗口以在表中显示大数据 [英] How to Pass the data from Main Window to Child Window to display large data in table using AngulaJS

查看:23
本文介绍了如何使用AngulaJS将数据从主窗口传递到子窗口以在表中显示大数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前我提出这个问题的主要目的是避免在 <td></td> 中显示大数据.因此,我想通过单击表格元素在新窗口中显示数据.目前我正在使用 AngularJS 显示表格.我做了很多研究,但无法获得输出.

我想以与此链接中显示的方式类似的方式,但不是从输入框中获取值,我想从 td 单元格中的 ng-repeat 获取值,并且当单击单元格时,应弹出新窗口向上

将数据传递到新窗口教程

下面是我的表的演示,我在其中传递大数据

{{list.DATA}}

大表演示

上面是我的桌子,正如你在表格中看到的那样.DATA 列非常大(实际长度大约为 500 个字符,但我显示的数据很少)所以我只想保持单击此处的字样.当用户点击时,它应该在新窗口中打开并显示数据.

解决方案

您可以通过以下步骤做同样的事情:

注意:新窗口在 plunker 中不起作用.因此,您必须在本地实时尝试此操作.

我在以下 plunker 链接中更新了相同内容,

https://plnkr.co/edit/lQ92O3?p=preview

步骤 1:更改您的 如下

<td>{{list._id.$id}}</td><td>{{list.OPERATION}}</td><td>{{list.STATUS}}</td><td ng-click="showText(list.DATA, $index)">{{shortText(list.DATA)}}</td></tr>

第 2 步:在控制器中添加两个方法,如下所示

var app = angular.module('studentApp', []);app.controller('StudentCntrl', function($scope,$http, $window) {$http.get('data.json').then(function (response){控制台日志(响应.数据.页面);$scope.opMessageLogs = response.data});$scope.shortText = 函数(数据){if(data && data.length > 20) {返回 data.substring(0, 20) + '..';}返回数据;};$scope.showText = 函数(数据,索引){var $popup = $window.open("Popup.html", "popup" + index, "width=250,height=100,left=10,top=150");$popup.data = 数据;};});

第 3 步:创建一个新页面 Popup.html 并在下面添加 html

<头><title></title><身体><script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.9/angular.min.js"></script><script type="text/javascript">var app = angular.module('MyChildApp', [])app.controller('MyChildController', function ($scope, $window) {$scope.data = $window.data;});<div ng-app="MyChildApp" ng-controller="MyChildController">数据:<span ng-bind="data"></span>

</html>

建议:您可以尝试使用 jquery 对话框(或)其他对话框代替新窗口

Hi Currently my main intention of the question is avoid displaying large data in the <td></td> . So instead of that I want to display the data in the new window by clicking on the element of the table. Currently I am displaying the table using the AngularJS. I have done much research but not able to get the output.

I want in the similar way as show in this link, But instead of getting the value from Input box I want to get the value from ng-repeat in the td cell and ,when the cell is clicked new window should be popped up

Passing Data to New window Tutorial

Below is the demo of the my table where I am passing the large data in

<td>{{list.DATA}}</td>

Demo of the large table

Above is my table ,as you can see in the table. DATA column is very large(Around 500 Characters length in real but i have shown little less data) so I just want to keep click here kind of word. When user clicks then it should open in the new window and show the data.

解决方案

You can do the same thing with below steps:

Note: New window won't work in the plunker. So you have to try this in realtime in your local.

I have updated the same in the following plunker link,

https://plnkr.co/edit/lQ92O3?p=preview

Step 1: Change your <tr> as below

<tr class="features" ng-repeat="list in opMessageLogs">
                        <td>{{list._id.$id}}</td>
                        <td>{{list.OPERATION}}</td>
                        <td>{{list.STATUS}}</td>
                        <td ng-click="showText(list.DATA, $index)">{{shortText(list.DATA)}}</td>
                    </tr>

Step 2: Add two methods in your controller as below

var app = angular.module('studentApp', []);

app.controller('StudentCntrl', function($scope,$http, $window) {
    $http.get('data.json').then(function (response){
                  console.log(response.data.pages);
                $scope.opMessageLogs = response.data
        });

    $scope.shortText = function(data) {
      if(data && data.length > 20) {
        return data.substring(0, 20) + '..';
      }

      return data;

    };

    $scope.showText = function(data, index) {
      var $popup = $window.open("Popup.html", "popup" + index, "width=250,height=100,left=10,top=150");
      $popup.data = data;
    };
});

Step 3: Create a new page Popup.html and add below html

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
</head>
<body>
    <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.9/angular.min.js"></script>
    <script type="text/javascript">
        var app = angular.module('MyChildApp', [])
        app.controller('MyChildController', function ($scope, $window) {
            $scope.data = $window.data;
        });
    </script>
    <div ng-app="MyChildApp" ng-controller="MyChildController">
        Data: <span ng-bind="data"></span>
    </div>
</body>
</html>

Recommendation: Instead of new window you can try a modal dialog with jquery dialog (or) other dialogs

这篇关于如何使用AngulaJS将数据从主窗口传递到子窗口以在表中显示大数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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