【问题标题】:Display table when ng-click based on the idng-click 时根据 id 显示表格
【发布时间】:2016-10-06 18:44:30
【问题描述】:

我有以下角脚本,它只是创建一个对象列表:

//To get the existing records
$scope.get_records = function(){
  filter_data = {set__iexact: $scope.final_data.set};
  bin.get(filter_data,
        function(data){
        $scope.main_list = data['objects'];
        console.log($scope.main_list);
        angular.forEach($scope.main_list, function(f) {

        });
    },function(data, status){
            console.log('Stage1: Internal error while loading initial data:'+status );
        }
)};

每条记录中唯一的字段是 id。我将这些 id 显示为 HTML 中的表格 (tr)。

<table class="table table paleblue table-fixed">
    {%verbatim %}
    <tr align="center" ng-repeat="f in main_list" ng-cloak>
        <td><button class="btn btn-small">{{f.id}}</button></td>
    </tr>
</table>

我的目标是在当前td 下方显示一个表格,该表格仅包含该特定 id 的元素。我怎样才能做到这一点?如何获取该特定 ID,以便我可以将其与 set 一起过滤?有什么想法吗?

【问题讨论】:

  • “我如何获得 id” ...您是说 f.id 不正确吗?问题/问题陈述不是很清楚
  • f.id 是正确的。但我需要获取该特定 ID 的对象并显示在表格中。 :)
  • 这样做的问题具体是什么?
  • 如何获取该特定 id 的表?如何传递该 id 来获取数据
  • ng-click="controllerFunction(f)"

标签: javascript python html angularjs django


【解决方案1】:

您必须添加:

0 - 过滤器:第二行将具有要过滤的其他元素的 ID,在我的情况下将是父行。

<tr align="center" ng-repeat="f in main_list" ng-cloak>

会改成

<tr align="center" ng-repeat="f in main_list |  filter:{father:selected}" ng-cloak>

1 - 设置过滤器:当点击Id set the filter with the id value, in my case I click a custom link, and set the Id as$scope.selected`来过滤其他行中的这个元素:父行。

<td><button class="btn btn-small">{{f.id}}</button></td>

会改成

<td><a ng-click="$parent.selected=element.id">Show sons of {{element.id}}</a></td>

如您所见,我使用$parent.selected。因为当您处于 ng-repeat 中时,您处于 CONTROLLER SCOPE 的 SUB SCOPE 中。

检查 Plunkr:http://plnkr.co/edit/vtsOsBFzDPXEPg3QW5yn?p=preview

【讨论】:

    猜你喜欢
    • 2016-10-27
    • 1970-01-01
    • 2020-06-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多