0
我有更新Salesforce的問題。 在事件模糊時,我需要表格單元格的新結果,傳遞給角度控制器,然後在salesforce中更新聯繫人。如果沒有監視,它會將選定的對象傳遞給遠程操作,而不會出現錯誤,但是不是初始的,而是編輯後的字段。我嘗試添加手錶,重新嘗試這篇文章http://blogs.microsoft.co.il/choroshin/2014/03/26/angularjs-watch-for-changes-in-specific-object-property/,但手錶給出了錯誤「$ scope.ContactData.map不是函數」。如何在角度控制器中查看可更改參數
我的角度控制器
var app = angular.module('MyApp',[]);
app.controller('myController',function($scope,VFRemotingFactory){
$scope.mcm = {};
VFRemotingFactory.getData().then(
function(result){
$scope.ContactData = result;
}
);
$scope.$watch(function($scope) {
return $scope.ContactData.map(function(obj) {
return obj.FirstName
});
},
function (newVal) {},
true);
$scope.orderByMe = function(x) {
$scope.myOrderBy = x;
}
$scope.editMe = function (obj) {
obj.target.setAttribute("contenteditable", true);
obj.target.focus();
}
$scope.NotEditMe = function (obj, contact){
obj.target.setAttribute("contenteditable", false);
UpdateContact(contact);
});
app.factory('VFRemotingFactory',function($q,$rootScope){
var factory = {};
factory.getData = function(searchText){
var deferred = $q.defer();
GetAllContactsByFilter(function(result){
$rootScope.$apply(function(){
deferred.resolve(result);
});
}, searchText);
return deferred.promise;
}
return factory;
});
function GetAllContactsByFilter(callback, searchText){
if(searchText == undefined){
searchText = '';
}
Visualforce.remoting.Manager.invokeAction('{!$RemoteAction.ContactsController.GetAllContactsByFilter}',
searchText,
callback,
{escape: false}
);
}
function UpdateContact(Contact){
Visualforce.remoting.Manager.invokeAction('{!$RemoteAction.ContactsController.UpdateContact}',
Contact,
function(result,event){},
{escape: false}
);
}
</script>
我的頁面
<tr ng-repeat="contactVar in ContactData | orderBy:myOrderBy | filter:mcm.searchText"/>
<td contenteditable="false" ng-dblclick="editMe($event)" ng-blur="NotEditMe($event,contactVar)"> {{contactVar.FirstName}}</td>
<td contenteditable="false" ng-dblclick="editMe($event)" ng-blur="NotEditMe($event,contactVar)"> {{contactVar.LastName}}</td>
<td contenteditable="false" ng-dblclick="editMe($event)" ng-blur="NotEditMe($event,contactVar)"> {{contactVar.Phone}}</td>
我的遙控器
public class ContactsController {
@RemoteAction
public static List<Contact> GetAllContactsByFilter(String searchText){
String searchString = '%' + searchText + '%';
List<Contact> contactList = [SELECT FirstName, LastName, Phone, Email, Title, Account.Name FROM Contact];
return contactList;
}
@RemoteAction
public static void UpdateContact(String contact){
System.debug(contact);
Contact contactForUpdate = new Contact();
contactForUpdate.FirstName = contact.substringBetween('FirstName=', ',');
contactForUpdate.LastName = contact.substringBetween('LastName=', ',');
contactForUpdate.Phone = contact.substringBetween('Phone=', ',');
}
}
的[傳遞變量AngularJS控制器,最好的做法?](可能的複製http://stackoverflow.com/questions/11703477/pass-variables-to-angularjs-controller-best -實踐) –