我遇到更新Salesforce的问题。 在事件模糊时,我想要表格单元格的新结果,传递给角度控制器,然后更新salesforce中的联系人。没有监视,它将选择的对象传递给远程操作而没有错误,但是初始的,而不是编辑的字段。我尝试添加手表,对本文http://blogs.microsoft.co.il/choroshin/2014/03/26/angularjs-watch-for-changes-in-specific-object-property/提供了反响,但手表发出错误“$ scope.ContactData.map不是函数”。
My Angular Controller
<xs:element name="projects">
<xs:complexType>
<xs:sequence>
<xs:element ref="project" minOccurs="0" maxOccurs="unbounded">
<xsd:annotation>
<xsd:appinfo>
<annox:annotate target="getter">@com.fasterxml.jackson.annotation.JsonValue</annox:annotate>
</xsd:appinfo>
</xsd:annotation>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
我的页面
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
"project"
})
@XmlRootElement(name = "projects")
public class Projects {
protected List<Project> project;
@JsonValue
public List<Project> getProject() {
if (project == null) {
project = new ArrayList<Project>();
}
return this.project;
}
}
我的遥控器
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>
答案 0 :(得分:0)
我做了一个简化的小提琴。检查this。
var app = angular.module('MyApp', []);
app.controller('myController', ['$scope', function($scope) {
$scope.mcm = {};
$scope.ContactData = [{
Id: 1,
FirstName: 'ABC'
}, {
Id: 2,
FirstName: 'DEF'
}]
$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);
console.log(contact.Id);
console.log(contact.FirstName);
}
}]);
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<body ng-app="MyApp">
<div ng-controller="myController">
<table>
<tr ng-repeat="contactVar in ContactData">
<td contenteditable="false" ng-dblclick="editMe($event)" ng-mouseleave="NotEditMe($event,contactVar)"> {{contactVar.FirstName}}</td>
</tr>
</table>
</div>
</body>
&#13;