我有一個工廠,它對我的salesforce apex類執行JavaScript遠程處理並返回promise。我正在同時多次調用工廠方法,每次調用都會返回給我defer.promise。但不知何故,它總是每次都會給我打第一個電話。儘管在defer.resolve(response)過程中,我的服務器響應在factory方法內部是不同的,但在返回defer.promise時,它每次都返回相同的結果給控制器。我試過調試,但沒有找到任何成功。任何人都可以建議我做錯了什麼。defer.promise在angularJS中返回同時調用不同數據輸入的相同結果
這裏是我的工廠方法:
app.factory('FieldSetFactory', ['$q', '$log', function($q, $log) {
var fieldSet = {};
var defer = $q.defer();
fieldSet.getFields = function(scope,fieldSetName, objectName) {
this.scope = scope;
var self = this;
FieldSetController.getFieldSetInfo(fieldSetName,objectName,function(response, event) {
if(event.status) {
console.log('response =',response); //this prints the actual result returned from server for different calls with different parameters
defer.resolve(response);
}
else {
$log.error(event.message);
defer.reject(event.message);
}
});
return defer.promise;
}
return fieldSet;
}]);
我遵守了我的名字位指示作爲fieldSetJsController {CID!}其中{CID!}是由試圖使用it.This任何成分獨特,並通過爲了將控制器範圍設置爲單獨調用而不是每次都覆蓋它們,其他一些組件傳遞了一些數據。
app.controller('fieldSetJsController{!cid}', ['$scope', 'dataService',
'requestNotificationChannel','FieldSetFactory', function($scope,
dataService,
requestNotificationChannel,FieldSetFactory) {
FieldSetFactory.getFields($scope,$scope.fieldSetName,$scope.objectAPIName).then(function(response){
console.log("response in controller..............",response); //this response always shows reslut of first call and any subsequent calls return same defer.promise
$scope.fieldsetList = JSON.parse(response.replace(/&/g,'').replace(/quot;/g,'"'));
console.log("FiledSets..............",$scope.fieldsetList); //this is always printing same result for different calls with different parameter
});
}]);
這些是我的組件,它們用不同的{!cid}值調用相同的控制器來區分它們。
<c:FieldSetComponent objectAPIName="Applications__c"
fieldSet="Application_FieldSet_One" cid="Applications_FieldSet_One"
sectionTitle="Section 1" columns="2" textAlign="center">
</c:FieldSetComponent>
<c:FieldSetComponent objectAPIName="Applications__c"
fieldSet="Application_FieldSet_Second" cid="Applications_FieldSet_Second"
sectionTitle="Section 2" columns="2" textAlign="center">
</c:FieldSetComponent>
<c:FieldSetComponent objectAPIName="clcommon__Collateral__c"
fieldSet="Collateral_FieldSet_One" cid="Collateral_FieldSet_One"
sectionTitle="Section 3" columns="2" textAlign="center">
</c:FieldSetComponent>
我花了數小時,併爲此而瘋了。非常感謝,1分鐘內無法接受答案:) – Cyclotron3x3