javascript - 尝试获取对象返回 Uncaught TypeError : Object function ParsePromise()

标签 javascript parse-platform vue.js es6-promise

下面的代码根据id返回一个Document对象,然后根据对象找到对应的section。 document 是一个 Parse 对象,document.toJSON 将此对象转换为 Javascript 对象。 sections 是一个 Javascript 对象数组。

ma​​in.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 下):

ma​​in.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/

相关文章:

javascript - 给定一个点和一个距离,计算 map 上的一个点

java - 继承 ParseObject 子类 (Android)

javascript - 如何在Vue-Native方法中返回React-Native组件

javascript - 尝试在 Vue.js 中动态添加 id 时未定义 id

javascript - 获取 slider 居中元素的对象

javascript - 从 webapp 深度链接到 UPI 应用程序,例如 Google Pay

javascript - IE9 中的 XML DOM childNode 不支持 for..in 语句?

javascript - 在用户滚动时显示图像

objective-c - 解析地理查询总是空的

android - 通过单击来自 Parse 的推送通知打开 Activity