2016-12-30 117 views
-1

我們需要在收件箱中實現類型提前功能,但是當我們從$ http得到響應get無效JSON,所以我無法做到那。

以下方法,我使用視圖級

uib-typeahead="name for name in collections ($viewValue)" 

角:

$scope.collections = function(val) { 
        return $http.get('/Documents/DocumentsList/', { 
         params : { 
          stk : val 
         } 
        }).then(
          function(response) { 
           if (response.data.suggestions) { 
            $("[uib-typeahead-popup].dropdown-menu").css('display','block'); 
            return response.data.suggestions 
              .map(function(item) { 
               return item.term; 
              }); 
           }; 
          }); 
       }; 

JSON響應:

{} && { 
    "name": "John", 
    "age": 31, 
    "city": "New York" 
} 

如何修改無效JSON到瓦利d JSON,然後傳遞有效的響應。

+0

你爲什麼不解決實際的端點響應所以它是有效的JSON? – Phil

+0

在您的JSON響應中沒有看到「建議」。你如何期望它能夠工作? – Phil

+0

@菲爾:是的,你是對的。提供的json不是actula響應JSON唯一的示例格式 – CodeMan

回答

1

這將是更好的解決在源頭的問題,但是,如果你不能做到這一點,實現自己的響應變壓器

return $http.get('/Documents/DocumentsList/', { 
    params: { stk: val }, 
    transformResponse: function(data) { 
     return angular.fromJson(data.substring(6)); 
    } 
})...