Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Category.search(...).then is not a function #23

Open
409915016 opened this issue Oct 18, 2020 · 2 comments
Open

Category.search(...).then is not a function #23

409915016 opened this issue Oct 18, 2020 · 2 comments
Assignees
Labels
bug 确认的问题 管理后台
Milestone

Comments

@409915016
Copy link
Owner

409915016 commented Oct 18, 2020

问题描述

在管理后台打开分类详情页,http://localhost:8080/admin#/categories/${category_name} ,页面未能加载对应分类的详细内容,并报错

Category.search(...).then is not a function

并定位代码

//src/router-components/admin/Category.vue#79
Category
  .search("name", this.$route.params.name)
  .then(([category]) => {
    this.model = category;
    this.category = category.getCacheData();
});

解决思路

min-model 关于 search 函数的 demo

// Syntax: Model.search(column, query)

Contact
  .search('name', 'Mike') // maybe there are not just one Mike
  .search('memo', 'Engineer')
   // Yes, you can search a column without creating a indexer
   // `min-model` will use the last search result as the pre-flight data
   // in this search operation.
   .then(result => console.log(result))
  • 可能是 min-model 库版本差异,导致 search 函数不可用 ?
  • search 函数不是 Promise 形式的调用?

最终从编辑器代码提示知道 search 函数紧跟着还有 exec 函数,最后返回 Promise 回调。

官方文档的示例代码是有误的

最后修改为:

Category
  .search("name", this.$route.params.name)
  .exec()  //add exec function to fix this
  .then(([category]) => {
    this.model = category;
    this.category = category.getCacheData();
});
@409915016 409915016 self-assigned this Oct 18, 2020
@409915016 409915016 added bug 确认的问题 管理后台 labels Oct 18, 2020
@409915016 409915016 added this to the v1.0.0 milestone Oct 18, 2020
@409915016
Copy link
Owner Author

别忘了还要去作者的仓库提使用文档有误的 issues

@409915016
Copy link
Owner Author

问题描述

在管理后台打开分类详情页,http://localhost:8080/admin#/categories/${category_name} ,页面未能加载对应分类的详细内容,并报错

Category.search(...).then is not a function

并定位代码

//src/router-components/admin/Category.vue#79
Category
  .search("name", this.$route.params.name)
  .then(([category]) => {
    this.model = category;
    this.category = category.getCacheData();
});

解决思路

min-model 关于 search 函数的 demo

// Syntax: Model.search(column, query)

Contact
  .search('name', 'Mike') // maybe there are not just one Mike
  .search('memo', 'Engineer')
   // Yes, you can search a column without creating a indexer
   // `min-model` will use the last search result as the pre-flight data
   // in this search operation.
   .then(result => console.log(result))
  • 可能是 min-model 库版本差异,导致 search 函数不可用 ?
  • search 函数不是 Promise 形式的调用?

最终从编辑器代码提示知道 search 函数紧跟着还有 exec 函数,最后返回 Promise 回调。

官方文档的示例代码是有误的

最后修改为:

Category
  .search("name", this.$route.params.name)
  .exec()  //add exec function to fix this
  .then(([category]) => {
    this.model = category;
    this.category = category.getCacheData();
});

该问题使用 min-model 0.1.11 版本而消失,讨论结束

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 确认的问题 管理后台
Projects
None yet
Development

No branches or pull requests

1 participant