2017-08-23 53 views
0

我的問題是類似的線程動態錶行代採用NG-重複

Dynamic table creation with ng-repeat in angularjs

JSON看起來像這樣

{ 「ID」: 「字符串」, 「標記」: { 「nummin」:「整數」 「nummax」:「整數」 「主旨名稱」:「串」, } }

只是會有一個額外的功能,用戶將進入沒有需要被生成,然後該表將根據動態JSON生成的行文件將從數據庫中提取。在此先感謝

+1

你嘗試過什麼嗎?告訴我們JSON文件的外觀,並告訴我們關於表結構的想法。有了這些信息,我可以參考[ng-repeat](https://docs.angularjs.org/api/ng/directive/ngRepeat)。 – Wartoshika

+0

JSON看起來像這樣> { 「ID」: 「字符串」, 「標記」: { 「NumMin的」: 「整數」 「NumMax的值」: 「整數」 「主旨名稱」: 「串」, } } – PRIYANSHI

+0

好的。用戶應輸入要顯示的行數。這個數字是你的商標部分的索引嗎?這是一個行數量?標記部分應該顯示在父表內嗎? – Wartoshika

回答

0

嘗試this JS-Fiddle

讓我知道這是否幫助你!

let app = angular.module('app', []); 
app.controller('ctrl', ['$scope', ($scope) => { 

    $scope.numberOfRows = 0; 
    $scope.data = []; 

    $scope.$watch('data',() => { 
     console.log($scope.data); 
    }, true); 

}]); 
app.filter('range', function() { 
    return function (input, total) { 
     total = parseInt(total, 10); 

     for (let i = 0; i < total; i++) { 
      input.push(i); 
     } 
     return input; 
    }; 
}); 


<div ng-app="app"> 
<div ng-controller="ctrl"> 
    <input type="number" ng-model="numberOfRows" /> 
    <br /> 
    <table width="100%"> 
    <tr> 
     <th>nummin</th><th>nummax</th><th>...</th> 
    </tr> 
    <tr ng-repeat="i in [] | range:numberOfRows"> 
     <td> 
     <input type="number" ng-model="data[i].nummin" /> 
     </td> 
     <td> 
     <input type="number" ng-model="data[i].nummax" /> 
     </td> 
     <td>...</td> 
    </tr> 
    </table> 
</div> 
</div> 
+0

感謝您的幫助,但在這個thead也出現n次,但我希望它只出現一次,這是固定的我該如何修改它。 – PRIYANSHI

+0

這是我的小提琴:https://jsfiddle.net/fuymqf8z/2/請看一下 – PRIYANSHI

+0

我無法理解你的問題。你的意思是索引或表格標題不止一次地表達? – Wartoshika