私はlaravelとangularjsを使用してソーシャルアプリに取り組んでいます。
ヘルパーを使用してユーザー関係を確認すると、状況が発生します。
**Html**
//showing users other info
<div ng-repeat="user in data">
<a ng-click=checkuser(user.id,checkrelation(user.id))>
{=checkrelation(user.id) =} <a>
</div>
**js**
//scope to hold user's data
//i get this info using service for the visiting user
$scope.data = myservice.userinfo();
//scope to hold users current subscriber info using service
$scope.allsubscriber = myservice.usersubscriber();
//check user relation and return text accordinglly
$scope.checkrelation = function(id){
//if user found
if($scope.allsubscriber.indexOf(id) != 1){
return "fellow";
}else{
// not found
return "subscribe";
}
}
$scope.checkuser = function(id,text){
if(text === "subscribe"){
//make ajax call to save user subscriber
//here i want to reload the user status which is checked by helper
}else
return false;
}
}
ユーザーが現在のユーザーの友人でない場合は、それに応じて追加されます。問題は、ページの読み込み時に変更が表示されるため、ページをリロードせずにユーザーがクリックしたときに {=checkrelation(data.id)=} の変更を反映する方法です。テキスト上。どんな助けでも役に立ちます。