2015-02-09 58 views
0

我有一個相對簡單的問題,但無法找到它的解決方案呢。我正在使用Ember並使用查詢參數調用路由。代碼如下。Ember QueryParams with「=」character

從「ember」導入Ember;

export default Ember.ObjectController.extend({ 
    queryParams : ['user_id','custom_lis_person_name_given'] 
    user_id : null, 
    custom_lis_person_name_given : null 
}); 

所以現在可以說,我打電話我用下面的URL路徑,

localhost:4200/index.html#/route1?user_id=123456&custom_lis_person_name_given=hello 

現在查詢參數的值是

user_id = 123456 
custom_lis_person_name_given = hello 

,如果我現在我的網址更改爲看起來像

localhost:4200/index.html#/route1?user_id=12345=6&custom_lis_person_name_given=hello 
localhost:4200/index.html#/route1?user_id=123456=&custom_lis_person_name_given=hello 

現在th e值的計算方式如下:

user_id = 12345 or user_id=123456 
custom_lis_person_name_given = hello 

所以基本上這個值在查詢參數值中看到a = sign的地方結束。有沒有解決方法?我需要的USER_ID = 「12345 = 6」「123456 =」

也許有在控制器或路線一些鉤子可以做到這一點。我試過serializeQueryParamdeserializeQueryParam但它沒有幫助。

由於提前

+0

我有一個解決方法,在使用URL之前轉義queryParamter。我只是**逃生('123456 =')**,它的工作。但在應用程序中,url在後端被創建。如果我可以在UI端完全修復它會更好 – aneeshere 2015-02-09 08:17:43

回答

0

你嘗試過:

encodeURIComponent(url) 

那一個應該做的工作。請注意,您仍然需要對=符號進行編碼,因此該符號應該是正確的。

encdeURIencodeURIComponent之間的差異以及描述如下: Should I use encodeURI or encodeURIComponent for encoding URLs?在接受的答案。

編輯:

如果要手動編輯鏈接,並檢查是否正常工作,只是%3D取代=encodeURIComponent("=")結果。

+0

這種情況就像整個URL(ember route + query params)在java文件中生成並在瀏覽器中調用。是的,所以一個解決方案是從java端做逃生(url)。但我想知道是否有什麼我可以從UI方面做。 – aneeshere 2015-02-09 09:17:33

+0

'encodeURIComponent'是一個JavaScript函數:) – andrusieczko 2015-02-09 09:27:26

+0

我編輯了我的答案,檢查是否可以幫助你 – andrusieczko 2015-02-09 10:55:25