下面的代码根据id返回一个Document
对象,然后根据对象找到对应的section。 document
是一个 Parse 对象,document.toJSON
将此对象转换为 Javascript 对象。 sections
是一个 Javascript 对象数组。
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]
最佳答案
您似乎正在为 sections
数据分配 promise 。
更好的方法是再次链接 promise 以找到该部分,并在 promise 链的末尾返回结果:
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}
})
},
关于javascript - 尝试获取对象返回 Uncaught TypeError : Object function ParsePromise(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34959462/