不知道這是否是你想要的,但這裏是一個的jsfiddle:
http://jsfiddle.net/TBGDu/25/
如果我理解正確的話,你要顯示「豬乙腦AMIS噸」爲您按接受屁股行打開,然後切換到顯示您按下拒絕按鈕的行的字符串'您拒絕我'。
爲了您的原代碼,有幾個錯誤:
如果你想顯示爲每行,你需要有這2個變量的每一行。在我的jsfiddle中,我使用了一個數組。
var showacceptation = false;
var showdenied = false;
對於這段代碼,因爲真實顯示在每行的是獨立於其他行,並且依賴於它自己的狀態,那麼你應該提供一個參數,它(想想$指數)。
<button ng-click="refuse()"><strong>refuse</strong></button>
這意味着這將需要更改爲接受指示該行的參數。
$scope.refuse = function(){
//my function to refuse User +
showdenied = true;
}
同樣的錯誤如上,你需要使用$指數變量提供行號:
<p ng-show="showResult2()"><strong>you refuse me</strong></p>
我的jsfiddle:
HTML:
<body ng-app="NgHideShowApp">
<div ng-controller="AppCtrl">
<table>
<tbody>
<tr ng-repeat="user in users">
<td>{{user.name}}</td>
<td>
<button ng-click="accept($index)"><strong>accept</strong>
</button>
<button ng-click="refuse($index)"><strong>refuse</strong>
</button>
<p ng-show="showacceptation[$index]"><strong>je suis ton amis</strong></p>
<p ng-show="showdenied[$index]"><strong>you refuse me</strong></p>
</td>
</tr>
</tbody>
</table>
</div>
</body>
的JavaScript:
從您的代碼
angular.module('NgHideShowApp', [])
.controller('AppCtrl', [
'$scope',
function($scope){
$scope.users = [{name: 'firstUser'},
{name: 'secondUser'},
{name: 'User3'},
{name: 'User4'}
];
$scope.showacceptation = [false, false, false, false];
$scope.showdenied = [false, false, false, false];
$scope.accept = function(idx) {
var i = $scope.users[idx];
console.log('value2 i:',i);
$scope.showacceptation[idx] = true;
$scope.showdenied[idx] = false;
};
$scope.refuse = function(idx) {
$scope.showdenied[idx] = true;
$scope.showacceptation[idx] = false;
};
}
]);
變化:
這裏,$指數提供指示該行。
<button ng-click="refuse($index)"><strong>refuse</strong>
</button>
我們可以在變量的值上使用ng-show,以便用於2段。請注意,showacception和showdenied現在變量數組。事實上,他們現在$範圍對象的一部分:裏面的NgHideShowApp控制器
<p ng-show="showacceptation[$index]"><strong>je suis ton amis</strong></p>
<p ng-show="showdenied[$index]"><strong>you refuse me</strong></p>
:
這表示每行顯示是否接受或拒絕的消息。最初,沒有顯示。所以一切都設置爲false。
$scope.showacceptation = [false, false, false, false];
$scope.showdenied = [false, false, false, false];
最後,2返工$範圍方法。點擊按鈕後,顯示接受或拒絕信息。顯示另一個隱形的可見性:
$scope.accept = function(idx) {
var i = $scope.users[idx];
console.log('value2 i:',i);
$scope.showacceptation[idx] = true;
$scope.showdenied[idx] = false;
};
$scope.refuse = function(idx) {
$scope.showdenied[idx] = true;
$scope.showacceptation[idx] = false;
};
希望幫助!
感謝這麼多,我做我想做的最後! http://jsfiddle.net/TBGDu/28/ – user2587877