2017-03-20 74 views
1

我的表如下插入在NG重複表中的獨立變量範圍值

<tr ng-repeat-start="x in referral"> 
<td>{{x.id}}</td> 
<td>{{x.name}}</td> 
<td>{{x.region}}</td> 
<td><button data-ng-click="request(x.id)">Request Info</button></td> 
<td><span>{{x.upload_msg}}</span></td> 
</tr> 

和代碼如下:

referral.list($scope.user_id).then(function(response){ 
    $scope.referral=response.data.data; 
    for (i=0;i< ($scope.referral).length; i++){ 
    $scope.referral[i].upload_msg=""; 
    } 
}); 

最後一列初始化爲空。 現在,當有人點擊該按鈕時,它會檢查在一定條件是否滿足或不使用下面的函數在JS

$scope.request=function(id){ 
data={"user_id":id}; 
referral.request(data).then(function(response){ 
    console.log(response); 
    $scope.upload_msg=response.data; 
}); 
} 

功能是除了一個事實,好顯示一條消息,當我檢查狀態表中的一行,它顯示了所有行中的上傳消息的值。我瞭解它,因爲我在表中插入一個範圍變量。

恐怕我不知道如何單獨顯示每個行upload_msg值。

幫助將十分讚賞。

+0

一個想法是添加一個「上傳」屬性以便您可以在最後的td – CyrillC

+0

中添加'ng-if =「x.uploaded」',或者如果每個用戶的上傳消息不同,則將其直接添加到用戶中並使用x.upload_message顯示它。 – CyrillC

+0

我面臨的問題是如何更新「已上傳」屬性只是針對該特定行而不是影響所有行 –

回答

4

的想法是整個x對象傳遞給你的request方法,並相應地更新它。

$scope.request=function(x){ 
data={"user_id":x.id}; 
referral.request(data).then(function(response){ 
    console.log(response); 
    x.upload_msg=response.data; 
}); 
} 

$scope.upload_msg財產在表中爲整個控制器進行定義,而不是一行。所以,當你更新了$scope.upload_msg屬性,它是在你的表中每一行更新。隨着x.upload_msg,你將有每行的屬性。

+0

工作完美。非常感謝。 –

2

強似只是x.id要求的方法,通過完整的X

<td><button data-ng-click="request(x)">Request Info</button></td> 

,並要求功能如下:

$scope.request=function(ref){ 
data={"user_id":ref.id}; 
referral.request(data).then(function(response){ 
    console.log(response); 
    ref.upload_msg=response.data; 
}); 
} 
+1

作品了。謝謝您的幫助。 –