books.js 1.0 KB

1234567891011121314151617181920212223242526272829303132333435
  1. import httpRequestApi from '../../../utils/APIClient';
  2. Page({
  3. data: {
  4. allBooks: []
  5. },
  6. onLoad: function (options) {
  7. wx.setNavigationBarTitle({
  8. title: '全部课本'
  9. })
  10. httpRequestApi.getAllBooks(1, 10).success((res) => {
  11. const books = res.data.data.list;
  12. const booksTemp = [];
  13. books.forEach(item => {
  14. let temp = {};
  15. temp.id = item.id;
  16. temp.iconImg = item.iconImg;
  17. temp.title = item.title.substring(0,5);
  18. booksTemp.push(temp);
  19. });
  20. this.setData({
  21. allBooks: booksTemp
  22. })
  23. console.log(this.data.allBooks)
  24. });
  25. },
  26. goToBook: function(e){
  27. console.log(e.currentTarget.dataset)
  28. let id = e.currentTarget.dataset.id;
  29. let title = e.currentTarget.dataset.title;
  30. wx.navigateTo({
  31. url: `../singleBook/singleBook?id=${id}&title=${title}`
  32. })
  33. }
  34. })