使用FatFractal JavaScript(HTML5)SDK調用grabBagAdd()方法時出現錯誤。對於這個特定的問題,我的數據模型很簡單,只涉及兩種對象類型:自定義的Team對象和默認的FFUser對象。FatFractal grabBagAdd() - 錯誤400:無法將NULL項添加到對象的抓包
相關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 observables以在本地存儲數據。產生錯誤的用例中的相關步驟如下:
在用戶登錄後從我的應用程序的後端提取團隊。下面,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
是一個可見的綁定到選擇菜單的值,幷包含來自self.teams
的團隊對象之一。此外,self.addMemberEmail
是綁定到用戶名輸入框的值的可觀察值。
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"}
不知道做出錯誤的東西。任何幫助,將不勝感激!
謝謝,剛剛添加一個ffUrl屬性到我的JS對象,並完美的工作! – 2013-02-22 05:09:36