0
我有一個模型,我想以做額外的工作數據添加parse方法(設立日期字段moment.js對象)。Parse.Collection.fetch不採取「解析:真正的」選項考慮
但功能沒有被調用(包括模型和集合)。
集合:
class SomethingCollection extends Parse.Collection
model: SomethingModel
parse: ->
console.log('parse from collection')
型號:
class SomethingModel extends Parse.Object
className: 'Something'
parse: ->
console.log('parse from model')
從一個觀點:
@collection = new SomethingCollection()
@listenTo(@collection, 'add', -> console.log('fire add event'))
@collection.fetch(parse: true, silent: false, add: true)
編輯:
似乎在Parse.Query.find發生回調,請參見下面的代碼註釋。 所以它不能在初始化方法進行爲好,但還有什麼地方?我懷疑Parse.Object是不是Bakbone.Model如此相似
find: function(options) {
var self = this;
options = options || {};
var request = Parse._request({
route: "classes",
className: this.className,
method: "GET",
useMasterKey: options.useMasterKey,
data: this.toJSON()
});
return request.then(function(response) {
return _.map(response.results, function(json) {
var obj;
if (response.className) {
obj = new Parse.Object(response.className); // <- no attributes or options used, blank object
} else {
obj = new self.objectClass(); // <- no attributes or options used, blank object
}
obj._finishFetch(json, true); // <- magically do things out of any constructor or parse function
return obj;
});
})._thenRunCallbacks(options);
},