gpt4 book ai didi

javascript - 无法使用 Angular.js 动态启用文本字段

转载 作者:行者123 更新时间:2023-11-28 05:30:59 25 4
gpt4 key购买 nike

我有一个问题。我需要使用 angular.js 动态启用我的文本字段,但它没有发生。我在下面解释我的代码。

<tr ng-repeat="gl in galleryDatas">
<td><input type="checkbox" ng-change="clickedRow(gl.checked,$index)" name="" ng-model="gl.checked"> {{$index+1}}</td>
<td><img ng-src="upload/{{gl.image}}" border="0" name="image" style="width:100px; height:100px;" /></td>
<td><textarea id="address" name="desc" class="form-control oditek-form" placeholder="Add comment" rows="6" ng-model="gl.description" style="height:70px" ng-readonly="gl.galComnt"></textarea></td>
<td>
<a class="btn btn-xs btn-success" title="Edit" ng-click="editComment(gl.gallery_id,$index,gl.description)"><i class="fa fa-pencil-square-o fa-fw"></i>{{gl.galEDit}}</a>
</td>
</tr>

我的 Controller 端代码如下。

$http({
method:'POST',
url:"php/customerInfo.php",
data:imageData,
headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
}).then(function successCallback(response){
$scope.formDiv=false;
$scope.gallery=true;
$scope.galleryDatas=[];
for(var i=0;i<response.data.length;i++){
var data={'gallery_id':response.data[i]. gallery_id,'subcat_id':response.data[i].subcat_id,'image':response.data[i].image,'description':response.data[i].description,'galComnt':true,'galEDit':"Edit"};
$scope.galleryDatas.push(data);
}
}

在这里,我需要当用户单击编辑按钮时,相应的行描述字段将是可编辑的。我的代码如下。

$scope.editComment=function(galid,index,comnt){
if($scope.galleryDatas[index].galEDit=="Edit"){
$scope.galleryDatas[index].galEDit="Update";
$scope.galleryDatas[index].galComnt=false;
}
}

但在这里它不起作用。在这里,我需要当用户单击任何行编辑按钮时,相应的行文本区域将是可编辑的。请帮助我。

最佳答案

你不应该使用index,这会导致困惑(当你在ng-repeat上使用更多过滤器时更是如此),而只是传递一个 >gl 对象到 editComment 函数。您在对象中所做的任何更改都会反射(reflect)到它的原始引用和 View 上。

ng-click="editComment(gl)"

代码

$scope.editComment=function(gl){
if(gl.galEDit=="Edit"){
gl.galEDit="Update";
gl.galComnt=false;
}
}

clickedRow 函数执行相同的操作。

关于javascript - 无法使用 Angular.js 动态启用文本字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39701761/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com