我尝试按照此post的建议从Pointer
检索字段,但我总是undefined
。
这是我的表Publication
的样子:
userId
- > User
subCategoryId
- > SubCategory
title
description
我的SubCategory
表:
categoryId
- > Category
name
isActive
这是我的尝试(桌子上只有一排):
var user = Parse.User.current();
var User = Parse.Object.extend("User");
var userQuery = new Parse.Query(User);
userQuery.equalTo("objectId", user.id);
var Publication = Parse.Object.extend("Publication");
var publicationQuery = new Parse.Query(Publication);
publicationQuery.include("subCategoryId");
publicationQuery.matchesQuery("userId", userQuery);
publicationQuery.find({
success: function(publications) {
console.log(publications[0].get("title"));
// This one returns undefined
console.log(publications[0].get("subCategoryId"));
}, error: function(error) {
// Nothing here as suggested by @adolfosrs
console.log(error);
}
});
我需要的是:
publications[0].get("subCategoryId").get("name");
但显然后者抛出:
Uncaught TypeError: Cannot read property 'get' of undefined
答案 0 :(得分:2)
如果您的解析数据库中有指针,如下所示,则无需使用objectIds。
您应该拥有的数据是这样的:
公开:
Pointer <_User>
)Pointer <SubCategory>
)String
)String
)子类别:
Pointer <Category>
)String
)boolean
)因此,如果您按预期保存数据,则必须执行以下操作:
var currentUser = Parse.User.current();
var Publication = Parse.Object.extend("Publication");
var publicationQuery = new Parse.Query(Publication);
publicationQuery.equalTo("user", currentUser);
publicationQuery.include("subCategory");
publicationQuery.find({
success: function(publications) {
console.log(publications[0].get("title"));
// This one returns undefined
console.log(publications[0].get("subCategory").get("name");
}
});