Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/68.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在表格中选择ng change_Javascript_Jquery_Angularjs_Asp.net Mvc - Fatal编程技术网

Javascript 在表格中选择ng change

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

我一直在寻找答案,但找不到任何地方

我有一个表,它有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: 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.
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
        }
    }
}