2016-01-23 71 views
1

以下代码基于其id返回Document对象,然后根据对象找到其相应的部分。 document是一个Parse对象,并且将此对象变成一个Javascript对象。 sections是Javascript对象的数组。尝试获取对象返回未捕获的TypeError:对象函数ParsePromise()

main.js:

data() { 
    return { 
     id: '', 
     document: {}, 
     sections: [], 
     content: '' 
    } 
    }, 

    route: { 
    data ({ to }) { 
     return store.first(to.params.id).then((document) => ({ 
     document: document.toJSON(), 
     sections: store.findSection(document).then((result) => this.sections = result) 
     })) 
    } 
    }, 

store.js:

const store = {} 

store.findSection = (obj) => { 
    const Section = Parse.Object.extend('Section') 
    const query = new Parse.Query(Section) 
    query.equalTo('document', obj) 
    return query.find().then((results) => 
    _.map(results, (result) => 
     result.toJSON() 
    ) 
) 
} 

export default store 

出于某种原因,store.findSelection引发此错误:

Uncaught TypeError: Object function ParsePromise() { 
    _classCallCheck(this, ParsePromise); 

    this._resolved = false; 
    this._rejected = false; 
    this._resolvedCallbacks = []; 
    this._rejectedCallbacks = []; 
    } has no method 'all' 

可能是什么亲瑕疵,以及如何解决它?

编辑:

奇怪的是,如果我做这样的事情(route下):

main.js:

methods: { 
    submit() { 
     store.findSection(store.transform(this.document)).then((result) => this.sections = result) 
    } 
    } 

store.js:

store.transform = (obj) => { 
    obj.className = 'Document' 
    return Parse.Object.fromJSON(obj) 
} 

store.findSection工程和输出正确的事情:[Object, Object, Object]

回答

2

你似乎是指派的承诺sections数据。

一个更好的办法是链条的承诺再次找到段,并在承诺链的末端返回结果:

return ...then((document) => { return findSection(document)}) 
.then((sections) => ({ 
    document: document.toJSON(), 
    sections: sections 
}) 

的另一种方式将密切关注document数据更改和使用vue-async-data插件(https://github.com/vuejs/vue-async-data)更新部分(注意:路由器将只被用于设置document在这种情况下):

watch { 
    document: reloadAsyncData 
}, 
asyncData() { 
    return store.findSection(document).then((result) => { 
     return {sections:result} 
    }) 
}, 
相关问题