我有一个Ionic应用程序,我正在搜索用户。当搜索返回结果时,我希望能够关注或取消关注该用户。
//search
$scope.searchPro = function(){
var query = new Parse.Query(Parse.User);
var searchinpu = $('#search-input').val();
var searchinput = searchinpu.toLowerCase();
query.equalTo("username", searchinput); // find all the relative users
query.find({
success: function(results) {
//Return User and foreach loop
var searchcon = "";
for (var i in results){
var username = results[i].get("username");
var image = results[i].get("profile_pic");
var postimage = image.url();
var curUser = Parse.User.current();
//Second Query get follow button
var cquery = new Parse.Query(Activity);
cquery.matches("fromUser", curUser); // find if he or she follows or not
cquery.matches("toUser", username); // find if he or she follows or not
cquery.find();
var button = "<button class='button button-outline button-lighter follow'>Follow</button>";
searchcon += "<div class='search-re'>";
searchcon += "<div class='search-re-view'><img src="+postimage+"></img></div>";
searchcon += "<div class='search-re-small'><img src="+postimage+"></img></div>";
searchcon += "<h3>@"+username+"</h3>";
searchcon += button;
searchcon += "</div>";
}
搜索用户并返回结果正常。问题是第二个查询。我无法检查当前用户是否跟踪了搜索到的用户。因此,我无法区分按钮应该是跟随按钮还是取消跟随按钮。 有没有办法显示这个按钮?