Javascript 在表格中选择ng change
我一直在寻找答案,但找不到任何地方 我有一个表,它有select和date输入Javascript 在表格中选择ng change,javascript,jquery,angularjs,asp.net-mvc,Javascript,Jquery,Angularjs,Asp.net Mvc,我一直在寻找答案,但找不到任何地方 我有一个表,它有select和date输入 <table id="tblCorrAction" class="table table-bordered table-striped table-hover table-condensed"> <thead> <tr style="height: 30px; background-color: #aeccea; color: #555; border: soli
<table id="tblCorrAction" class="table table-bordered table-striped table-hover table-condensed">
<thead>
<tr style="height: 30px; background-color: #aeccea; color: #555; border: solid 1px #aeccea;">
<th style="width:18%;">RArea</th>
<th style="width:37%;">P</th>
<th style="width:20%;">C</th>
<th style="width:25%;">CAction</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="ca in CASelectList">
<td>{{ca.QT}}</td>
<td>{{ca.CAPT}}</td>
<td>
<select name="caC_{{ca.QuesID}}" ng-model="item" class="form-control"
ng-selected="ca.Corrected" ng-required="true"
ng-change="GetCorrectedCAData(ca, item)"
ng-options="corr as corr.caText for corr in correctedOption">
<option value="">--Select--</option>
</select>
</td>
<td>
<span>
<input name="caDate_{{ca.QuesID}}" type="text" datepicker=""
ng-model="ca.caDate"/>
</span>
</td>
</tr>
</tbody>
</table>
In my controller
$scope.correctedOption = [{ caValue: 1, caText: 'Yes' }, { caValue: 2, caText: 'No' }];
第二:将id添加到输入
<input id="caDate_{{ca.QuesID}}" name="caDate_{{ca.QuesID}}" type="text" datepicker=""
ng-model="ca.caDate"/>
And in controller
if (item.caValue === 2) {
angular.element(document.querySelector("#caDate_" + ca.QuesID)).val("");
}
this also did not work. Error:Missing instance data for this datepicker
ng repeat
中的ca
与控制器中的$scope.ca
不同。执行$scope.ca
操作时,表示控制器上有一个名为ca
的$scope
变量。像这样,
var Controller = function($scope) {
$scope.ca = {
caDate: "some date";
}
}
您得到错误:无法设置未定义的的属性'caDate',因为$scope.ca
在$scope上不存在。
如果您想引用ng repeat
中每个CASelectList
中的值(我想这是您想要的),那么您只需将$scope.
放在ca
前面。因此,您的代码将如下所示
var Controller = function($scope) {
$scope.GetCorrectedCAData = function (ca, item) {
if (item.caValue === 2) {
ca.caDate = ""; // This will change the ca value of the certain ca in CASelectList
}
}
}
你能在控制器中发布与问题相关的要点吗。什么是$scope.ca
?CASelectList使用ng repeat填充表格。请看上表。因此,可以通过ca.caDate和ca.Corrected绑定输入和选择。因此,当用户选择“否”作为答案时,我想使用$scope.ca.caDate=”“删除所选日期,但它不起作用。caDate不会重置。如果(SelectCorrected.caValue==2){$scope.ca={caDate:“}}}不将其更改为$scope.ca=…
只需在ca.caDate=”之前删除$scope.
哦,我的错。让我再试一次谢谢你的回答。我知道ng repeat中的ca与控制器中$scope.ca中的ca不同。那么,如果没有$scope,如何实现双向绑定呢。虽然我第一次开始使用angular,但我的理解是,如果我必须更新视图中的任何内容,那么在您的示例中,我需要$scope,您不是双向绑定。您只需调用方法GetCorrectedCAData
传递从ng repeat
创建的对象ca
。您只需更改传入的对象,它恰好是CASelectList
中的一个对象。
var Controller = function($scope) {
$scope.ca = {
caDate: "some date";
}
}
var Controller = function($scope) {
$scope.GetCorrectedCAData = function (ca, item) {
if (item.caValue === 2) {
ca.caDate = ""; // This will change the ca value of the certain ca in CASelectList
}
}
}