2014-12-19 32 views
1

本網站上的第一個問題,我是django的新手,角度對我來說太露骨了。如何在ng-repeat過濾器中傳遞HoDjango views.py上下文數據變量

我正在嘗試在角度ng-repeat中使用過濾器,其中selectedUserId是一個context_dict變量。 我的角花括號是{ - }

我view.py - 從URL中獲得USER_ID

def profile(request, user_id): context = RequestContext(request) context_dict = {} context_dict['selectedUserId'] = user_id return render_to_response('rango/profile.html', context_dict, context)

我的NG-重複

<格數據-ng-repeat =「配置文件中的配置文件|過濾器:{userId:selectedUserId}:true」>

<h1>{{ selectedUserId }} Profile<h1> 
    <h2>{- profile.userId -}</h2> 

我怎樣才能讓我的selectedUserId渲染,我試過{%selectedUserId%}並沒有奏效。

謝謝。

回答

0

你呈現{{selectedUserId}}在h1標籤,所以在你的NG-重複你也應該使用{{ selectedUserId }}

<div data-ng-repeat="profile in profiles | filter:{ userId: '{{ selectedUserId }}' }: true"> 
+0

對不起,我這樣做,昨天一整天和它沒沒有工作。今天突然它的工作......我的問題是,我忘記把{{selectedUserID}}單引號和結果作爲角度而不是字符串的變量計算。謝謝 ! – Jack 2014-12-20 05:22:00

+0

哦,確實應該有{{selectedUserId}}的引號。我編輯了答案以添加它們。最好的祝福! – iulian 2014-12-20 08:10:08