我正在使用jQuery循環訪問數組,並將每個值與模型的用戶標識進行比較。如果找到匹配項,我將只顯示特定的文本。錯誤循環遍歷循環並在條件滿足時中斷
$.each current_user.get('following_ids'), (i, e) =>
console.log(@model.get('user')._id == e)
if @model.get('user')._id == e
@is_following = true
//break from loop if condition is met
return false
else
@is_following = false
//else continue looping through
return true
if @is_following
$(@el).find('.user_info .follow a').text "following"
else
$(@el).find('.user_info .follow a').text "follow"
但是我的代碼不工作,它總是返回我「跟隨」文本。我在這裏做錯了什麼?
我希望我可以upvote你的答案多次。謝謝你打在頭上的釘子!還愛你的替代解決方案,非常乾淨和高效。非常感謝! – Zhen
@珍:不用擔心,有時我喜歡拼圖:) –