BlogApp.Collections.Blogs = Parse.Collection.extend({
model: BlogApp.Models.Blog,
query: (new Parse.Query(BlogApp.Models.Blog)).equalTo("author", "xMQR0A1Us6").descending('createdAt').limit(9)
});
以上似乎不起作用。例如,我可以使用類中已有的列做各種事情,例如.equalTo("productType", "SHIRT")
,但我無法鏈接到存在於單獨的類User中的作者。限制查詢以獲取具有特定指針的所有項目(JavaScript - Parse.com)
我該如何限制查詢只從「作者」(一個指針)檢索等於存在於用戶類中的objectId的項目?
型號:
BlogApp.Models.Blog = Parse.Object.extend('MarketDesign', {
update: function(form) {
if (!this.get('ACL')) {
var blogACL = new Parse.ACL(Parse.User.current());
blogACL.setPublicReadAccess(true);
this.setACL(blogACL);
}
BlogApp.category.id = form.category;
this.set({
'title': form.title,
'url': form.title.toLowerCase()
.replace(/[^\w ]+/g,'')
.replace(/ +/g,'-'),
'category': BlogApp.category,
'comment': form.content,
'author': this.get('author') || Parse.User.current(),
'authorName': this.get('authorName') || Parse.User.current().get('username'),
'time': this.get('time') || new Date().toDateString()
}).save(null, {
success: function(blog) {
Parse.history.navigate('#/admin', { trigger: true });
window.location.reload();
},
error: function(blog, error) {
console.log(error);
}
});
}
});
您是否正在嘗試查找博客作者是*當前用戶*的博客?這很容易(並在我的答案的第一部分中描述)。我的回答的另一部分涉及OP中的id xMQR0A1Us6。該用戶名屬於哪個用戶,你從哪裏得到它?我編輯了我的答案以澄清。要查詢作者==當前用戶,你在這個答案中的代碼非常接近。重點是,我們傳遞* objects *來與指針字段進行比較。 – danh
此外,您網站的帖子處理的是比您想要解決的更復雜的問題。一旦你掌握瞭如何處理指針,你想要做的事情就很簡單而且容易。 – danh
以X開頭的Id只是隨機用戶的對象Id。我正在測試不同的查詢。該查詢將用於用戶的個人資料,顯示他們的所有帖子。所以至少在查看你自己的時候,你會需要當前用戶的objectId。 – santafebound