【发布时间】:2018-04-19 00:12:27
【问题描述】:
我一直在寻找这个问题的答案,但找不到任何地方。
我有一个有选择和日期输入的表格
<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' }];
所以现在我要做的是,如果在选择选项中使用选择是,那么用户可以在日期时间输入中输入值,如果用户选择否,则应该重置输入的值。我尝试了一些东西,没有一个成功
第一:
$scope.GetCorrectedCAData = function (ca, item) {
if (item.caValue === 2) {
$scope.ca.caDate = ""
}
}
this did not work. Error : Cannot set property 'caDate' of undefined
at ChildScope.$scope.GetCorrectedCAData
2nd : 添加 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
3rd:循环遍历 CASelectList 拼接行并添加拼接的行,其中包含空数据作为日期。我不想使用它,因为可能有很多很多记录。
日期选择器指令
ngControlMod.directive('datepicker', function () {
return {
require: 'ngModel',
link: function (scope, el, attr, ngModel) {
$(el).datepicker({
onSelect: function (dateText) {
scope.$apply(function () {
ngModel.$setViewValue(dateText);
});
}
});
}
};
});
【问题讨论】:
-
您能否在控制器中发布与问题相关的点。
$scope.ca是什么? -
CASelectList 使用 ng-repeat 填充表。
.请看上表。所以 input 和 select 可以被 ca.caDate 和 ca.Corrected 绑定。因此,当用户选择否作为答案时,我想使用 $scope.ca.caDate = "" 删除所选日期
标签: javascript jquery angularjs asp.net-mvc