如何从数据库中将数据填充到ui-grid的子网格中

时间:2014-12-11 08:17:25

标签: angularjs ng-grid angular-ui-grid

我正在尝试将数据库中的数据填充到angularjs ui-grid的子网格中,但是它不起作用这就是代码

`var User = $ resource(' / rest / daybook / sales_registertest /:id /?app_name = DAYBOOK_NEW& fields = *',{},{update:{method:' PUT'},查询:{         方法:' GET',         isArray:false     }});

var User1 = $ resource(' / rest / daybook / salesdetailtest /:id /?app_name = DAYBOOK_NEW& fields = *',{},{update:{method:' PUT& #39;},查询:{         方法:' GET',         isArray:false     }});

User.get(function(data) {

      for(i = 0; i < data.record.length; i++){
          var records;
       var id=data.record[i].sales_id;
    User1.get({
     sales_id: id
      }, function(resp) {
        // Handle successful response here
        records=resp.record;
        console.log(records);
      }, function(err) {
            // Handle error here
       });
          //alert(id);
    data.record[i].subGridOptions = {
      columnDefs: [ 
          {field:'sales_id'},
          {field:'product_id'},
          {field:'sale_qty'}, 
          {field:'sale_price'}, 
          {field:'sale_amount'}, 
          {field:'product_id'} ,
          {field:'updated_on'} 
      ]  
    };
    data.record[i].subGridOptions.data=records;


  }

$ scope.gridOptions.data = data.record; },function(err){

});`

我需要做的是,根据不同表格中主网格中行的id来获取子网格。我怎么能实现这个?

1 个答案:

答案 0 :(得分:-1)

$http.get('/data/500_complex.json')
    .success(function(data) {
      for(i = 0; i < data.length; i++){
       //parse the data object and check the database for any relations then grab those as an object and push it into the data[i].subGridOptions
        data[i].subGridOptions = {
          columnDefs: [ {name:"Id", field:"id"},{name:"Name", field:"name"} ],
          data: data[i].friends
        }
      }
      $scope.gridOptions.data = data;
    });