angularJs:单击按钮后如何加载表格数据
angularJs : how to load table data after clicking a button?
大家好,如果我的问题太长,我很抱歉,这是我在Stack over flow中的第一个问题:);我是angularJs的新手,所以我面临这个问题我试图制作一个按钮,将我通过http.get函数检索到的json数据加载到一个带有ng repeat的表中我想在点击按钮后加载数据
角度:
app.controller('dayRecord', function ($scope, $http) {
var date = dateToString("dailyData")
,http;
$scope.headers = ["company", "ticker", "ccy", "last", "close", "chg", "bid", "ask", "trades", "volume", "turnover"];
//LoadDate : function to load StockRecords for a given day
$scope.loadData = function () {
http = "http://localhost:63342/nasdak/app/data?date=";//the REST service Server to fetch the day stock recrod json data
http += date; //
$http.get(http)
.success(function (response) {
console.log(response);
$scope.first = response.balticMainList;
$scope.columnSort = {sortColumn: 'turnover', reverse: true};
});
}
$scope.loadData();
});
正如你在这里看到的:day记录控制器loadData函数,用于获取json数据
这是我试图加载的表的html代码
HTML
<div ng-controller="dayRecord" style="display: inline;">
<label for="dailyData">Show Stock For Day :</label>
<input type="text" id="dailyData" name="dailyData" >
<button id = "dailyStocksLoad" ng-click="loadData()">load</button>
</div>
<div class ="dailyViewContainer" ng-controller="dayRecord">
<div >
<h1>Baltic Main List</h1>
<table id ="myTable" >
<thead>
<tr >
<th ng-repeat="header in headers " ng-click="columnSort.sortColumn=header;columnSort.reverse=!columnSort.reverse">{{header}}</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="x in first | orderBy:columnSort.sortColumn:columnSort.reverse">
<td style="text-align: left">{{ x.company }}</td>
<td>{{ x.ticker }}</td>
<td>{{ x.ccy }}</td>
<td>{{ x.last }}</td>
<td>{{ x.close }}</td>
<td>{{ x.chg }}% </td>
<td>{{ x.bid }}</td>
<td>{{ x.ask }}</td>
<td>{{ x.trades }}</td>
<td>{{ x.volume }}</td>
<td>{{ x.turnover }}</td>
</tr>
</tbody>
</table>
</div>
当我调用控制器内部的函数时,一切正常
app.controller('dayRecord', function ($scope, $http) {
...
$scope.loadData = function () {
...
}
$scope.loadData();
});
但是当我点击按钮动态加载数据时,我无法加载它,我甚至用console.log(response)检查了响应,它显示http.get正在检索数据,但它没有在表上刷新它
嗯,问题可能是您将两段html分配给同一个控制器。把整个html包装成1个div元素,然后把ng控制器放在那里,如下所示:
<div ng-controller="dayRecord">
<div style="display: inline;">
<label for="dailyData">Show Stock For Day :</label>
<input type="text" id="dailyData" name="dailyData" >
<button id = "dailyStocksLoad" ng-click="loadData()">load</button>
</div>
<div class ="dailyViewContainer">
<div >
<h1>Baltic Main List</h1>
<table id ="myTable" >
<thead>
<tr >
<th ng-repeat="header in headers " ng-click="columnSort.sortColumn=header;columnSort.reverse=!columnSort.reverse">{{header}}</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="x in first | orderBy:columnSort.sortColumn:columnSort.reverse">
<td style="text-align: left">{{ x.company }}</td>
<td>{{ x.ticker }}</td>
<td>{{ x.ccy }}</td>
<td>{{ x.last }}</td>
<td>{{ x.close }}</td>
<td>{{ x.chg }}% </td>
<td>{{ x.bid }}</td>
<td>{{ x.ask }}</td>
<td>{{ x.trades }}</td>
<td>{{ x.volume }}</td>
<td>{{ x.turnover }}</td>
</tr>
</tbody>
</table>
</div>
</div>
相关文章:
- 如何使用url加载程序在webpack中导入多个图像
- 如何在生成下载文件时显示加载动画
- 有没有任何方法可以将控制器从文件加载到ui路由器$stateProvider中
- 将HTML表格导出到excel时,无法将数据加载到excel文件中
- 在AngularJS应用程序中加载JSON(加载谷歌电子表格)
- 如何在加载 html 页面时将表格设置为已在某个列滚动
- 将“加载更多”添加到从Google电子表格中通过$.getJSON接收的数据输出中
- 加载谷歌电子表格以使用传单进行可视化
- 可以在客户端延迟加载表格内容
- 自动加载一个html表格与组合框
- JQuery -加载表格并使用html()插入
- 如何在准备表格时显示加载程序
- Google apps脚本HTML选择从电子表格数据加载的选项
- 可能加载谷歌驱动器电子表格JSON未经同意屏幕
- 从表格中加载数据的柱状图上的反向序列
- jQuery-隐藏表格->重新加载页面后,我的表显示了几秒钟
- 将(大量加载公式的)Excel电子表格转换为用户友好的网络计算器
- Windows.表格.WebBrowser正在加载带有本地SVG文件的页面
- angularJs:单击按钮后如何加载表格数据
- 为什么我的表格在加载时出现,而不是我的图表