目前我有一個工廠使用包裝在$ http.get請求中的json文件。雖然不理想,但它適用於測試。我需要在SharePoint環境中測試相同的解決方案,但不允許使用json文件。最終,這將連接到一個網絡API調用。在工廠中使用值數組
如何指定工廠內的json值以允許測試?
(function() {
var personalViewFactory = function($http) {
var factory = {};
factory.getCustomers = function() {
return $http.get('relationshiptracker.json');
};
return factory;
};
personalViewFactory.$inject = ['$http'];
angular.module('customersApp').factory('customersFactory',
personalViewFactory);
}());
JSON
[
{
"Segment":"Trading",
"Title":"Narima Ajam ",
"Role":"Oil and Shipping Competency Center Manager ",
"Last Meeting Date":"1/1/2000",
"nextmeetingowner":"",
"CreatedDate":"9/14/2014",
"Modified":"9/14/2014",
"primaryaccountability":"Ajay Buti ",
"otherltEngaged":"Aylin Korkmaz, Carolyn Williams, Karthik Chandrasekar",
"upcomingdate":""
},
{
"Segment":"Upstream",
"Title":"Alison Kenney",
"Role":"IM/IT Manager - The Bridge; (NOLA) - The Bridge",
"Last Meeting Date":"8/5/2014",
"nextmeetingowner":"",
"CreatedDate":"1/2/2000",
"Modified":"2/15/2014",
"primaryaccountability":"Arnold",
"otherltEngaged":"Yero",
"upcomingdate":""
},]
這似乎太簡單了,所以我一定不能瞭解你的需求,因爲所有我看到你做的是做一個變種,你的JSON分配給它,然後在你的GetCustomers的調用返回。根據您的客戶端代碼在做什麼,可能將其包裝在承諾中。 – mccainz 2014-10-17 16:58:15
我可能會過度複雜化一個簡單的問題。我正在嘗試這個,但我錯過了一些東西。 http://jsfiddle.net/sharepointjason/zcrfty78/ – Jason 2014-10-17 17:15:40