2
我正在研究一个应用程序,该应用程序允许最终用户从下拉列表中运行查询并显示数据表。在表格中,每行都有一个按钮。如果最终用户点击按钮,我需要在我的程序中捕获该行的值以备后用。捕获按钮上的行数据单击Angularjs
我似乎无法让我的现有应用程序中工作。我是新来的角,看来这可能是问题,因为我能够完成这个足够简单的事情,当我将我的代码复制到小提琴没有角应用(见下文)。
https://jsfiddle.net/auLczhv7/
这里是我的代码(REST端点,这是一个SharePoint列表):
var spApp = angular.module('spApp', []);
spApp.controller('spListCtrl', function ($scope, $http) {
$scope.clickButton = function(){
var storeNum = $("#storeNum").val();
$http(
{
method: "GET",
url: "https://mypage.com",
headers: { "Accept": "application/json;odata=verbose" }
}
).success(function(data){
$scope.MyData = data.d.results;
}).error(function (data, status, headers, config) {
});
}
$scope.disputeButton = function(){
var stNum = $(this).parent().siblings(":first-child").text();
alert(stNum);
}
});
而且我的html:
<body>
<div id="headerWrap">
<div id="headerText">My App</div>
</div>
<div ng-app="spApp" id="appWrap">
<div ng-controller="spListCtrl">
<div id="storeSearchWrap">
<span style="font-family:Arial, Helvetica, sans-serif;font-weight:bold">Store Number: </span><select id="storeNum">
<option value="" class="storeNumOpt"></option>
</select>
<button id="searchBtn" ng-click="clickButton()">Search</button>
<button id="printBtn" onclick="printWindow()">Print Report</button>
</div>
<div id="spinner" style="padding-top:50px;padding-bottom:50px">
<div id="txtWrap">
<p id="waitTxt">Loading...</p>
</div>
</div>
<p id="searchContainer">Filter: <input type="text" ng-model="search"></p>
<table width="100%" cellpadding="10" cellspacing="2" class="myTbl-table">
<thead>
<tr>
<th>Store Number</th>
<th>Date</th>
<th>Sub</th>
<th>Lot</th>
<th>Line</th>
<th>Sku</th>
<th>PO Number</th>
<th>Qty Received</th>
<th>Dispute Qty</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="item in MyData| filter : search">
<td>{{item.StoreNumber}}</td>
<td>{{item.Date}}</td>
<td>{{item.Sub}}</td>
<td>{{item.Lot}}</td>
<td>{{item.Line}}</td>
<td>{{item.Sku}}</td>
<td>{{item.PONumber}}</td>
<td>{{item.QtyReceived}}</td>
<td><button class="disputeBtn" ng-click="disputeButton()">Dispute</button></td>
</tr>
</tbody>
</table>
</div>
</div>
</body>
我在做什么错?有没有更容易的方法来完成角度?
真棒,那工作!由于我倾向于回归到jQuery,因此我会牢记这一点,因为这是我熟悉的。谢谢! – Nate