使用 FatFractal JavaScript (HTML5) SDK 调用 grabBagAdd() 方法时出现错误。对于这个特殊问题,我的数据模型很简单,只涉及两种对象类型:自定义 Team 对象和默认的 FFUser 对象。
相关 FFDL 声明:
CREATE OBJECTTYPE FFUser (userName STRING, firstName STRING, lastName STRING, email STRING, active BOOLEAN, authDomain STRING, groups GRABBAG /FFUserGroup, notif_ids GRABBAG /FFNotificationID)
CREATE OBJECTTYPE Team (teamName STRING, members GRABBAG /FFUser)
CREATE COLLECTION /FFUser OBJECTTYPE FFUser
CREATE COLLECTION /Teams OBJECTTYPE Team
JS 对象声明:
function Team(data){
if(data){
this.clazz = data.clazz;
this.guid = data.guid;
this.teamName = data.teamName;
}
else{
this.clazz = "Team";
this.guid = null;
this.teamName = null;
}
return this;
}
function FFUser(data){
if(data){
this.clazz = data.clazz;
this.userName = data.userName;
this.firstName = data.firstName;
this.lastName = data.lastName;
this.email = data.email;
this.active = data.active;
this.guid = data.guid;
}
else{
this.clazz = "FFUser";
this.userName = null;
this.firstName = null;
this.lastName = null;
this.email = null;
this.active = null;
this.guid = null;
}
return this;
}
我只是试图将 FFUser 添加到选定团队的成员抓包中。我正在使用 KnockoutJS 绑定来显示我的 Web 应用程序的数据,并使用 KnockoutJS 可观察对象来在本地存储数据。产生错误的用例中的相关步骤如下:
用户登录后,从我的应用程序后端拉取团队。下面self.teams
是一个绑定到 HTML 选择菜单的可观察数组。
function loadTeams() {
ff.getArrayFromUri("/ff/resources/Teams",function(loadedTeams) {
if(loadedTeams.length > 0) {
for(var i = 0; i < teams.length; i++) {
var team = new Team(loadedTeams[i]);
self.teams.push(team);
}
}
else console.log("No teams to load!");
},function(statusCode,responseText) {
alert(JSON.parse(responseText).statusMessage);
});
};
用户从选择菜单中选择一个团队并输入用户名以添加为团队成员。提交后,将执行 grabBagAdd()。下面,self.selectedTeam
是一个绑定到选择菜单值的可观察对象,并包含来自 的 Team 对象之一self.teams
。此外,self.addMemberEmail
是一个绑定到用户名输入框的值的 observable。
self.addMember = function() {
if(self.addMemberEmail()) {
ff.getObjFromUri("/ff/resources/FFUser/(userName eq '" + self.addMemberEmail() + "')",function(user) {
if(user){
var member = new FFUser(user);
ff.grabBagAdd(member,self.selectedTeam(),"members",function() {
console.log("Added member to grabbag!");
},function(statusCode,responseText) {
alert(JSON.parse(responseText).statusMessage);
});
}
else alert("No users found with the provided username.");
},function(statusCode,responseText) {
alert(JSON.parse(responseText).statusMessage);
});
}
else alert("Must provide member email.");
};
FatFractal 返回400: Bad Request
错误如下:
FatFractal.handleGrabBagRequest 400, {"result":null,"statusMessage":"Cannot add NULL items to a object's grab bag"}
不知道该怎么做的错误。任何帮助,将不胜感激!