html - document.write a json vector to a table -


firstly orders:

app.controller('customerscontroller', ['$scope', '$http', function($scope,$http) {       $http.get("http://18ff2f50.tunnel.mobi/yii2-basic/tests/customers_json.json")       .success(function (response)        {         console.log("debug",response);        $scope.orders = response;       }); 

in order have detail:

    <div class="row" ng-repeat="x in orders|orderby:'order_id'">     ....     <div class="col right">       <button ng-click="vieworderdetails(x.detail)">订单详情</button>     </div> 

i have json vector (which returned server) stored in "detail" this:

"detail": "{\"4\":     {\"num\":2,      \"id\":\"4\",      \"name\":\"\\u86cb\\u7092\\u996d\",      \"price\":\"10.00\",\"total\":20},    \"6\":      {\"num\":1,       \"id\":\"6\",       \"name\":\"\\u626c\\u5dde\\u7092\\u996d\",       \"price\":\"10.00\",\"total\":\"10.00\"},     \"5\":       {\"num\":1,        \"id\":\"5\",        \"name\":\"\\u51b0\\u6dc7\\u51cc\",        \"price\":\"8.00\",\"total\":\"8.00\" }}"   $scope.vieworderdetails = function vieworderdetails(detail) {             var newwin = open('orderdetails.html','windowname','height=300,width=300');             newwin.document.write('html write...\n');             newwin.document.write(detail);              newwin.document.write('<input type="button" value="close window" onclick="window.close()">');         } 

i want displayed in new window this: enter image description here

how should document.write? thanks.

you can use $compile service compile template write new window:

app.controller('customerscontroller', function($scope, $http, $compile) {      $http.get("order.json").success(function(response) {         $scope.x = response;     });      $scope.vieworderdetails = function vieworderdetails(order) {          var newwin = open('', 'windowname', 'height=300,width=300');          var template =              '<div>' +                 '<table>' +                      '<tr ng-repeat="(key, value) in order">' +                          '<td>{{value.name}}</td>' +                         '<td>{{value.id}}</td>' +                         '<td>{{value.price}}</td>' +                         '<td>{{value.total}}</td>' +                     '</tr>' +                 '</table>' +                  '<input type="button" value="close window" onclick="window.close()">' +             '</div>';          $scope.order = order;         var table = $compile(template)($scope);          newwin.document.body.appendchild(table[0]);     } }); 

demo: http://plnkr.co/edit/pmccluymkpeymifwphrj?p=preview


Comments

Popular posts from this blog

java - UnknownEntityTypeException: Unable to locate persister (Hibernate 5.0) -

python - ValueError: empty vocabulary; perhaps the documents only contain stop words -

ubuntu - collect2: fatal error: ld terminated with signal 9 [Killed] -