template.js 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. const dataDemo = require('./dataDemo')
  2. /*
  3. <view class="container" id="main">
  4. <view class="header">
  5. <text class="title" value="排行榜"></text>
  6. </view>
  7. <view class="rankList">
  8. <scrollview class="list">
  9. {{~it.data :item:index}}
  10. {{? index % 2 === 1 }}
  11. <view class="listItem listItemOld">
  12. {{?}}
  13. {{? index % 2 === 0 }}
  14. <view class="listItem">
  15. {{?}}
  16. <view id="listItemUserData">
  17. <text class="listItemNum" value="{{= index + 1}}"></text>
  18. <image class="listHeadImg" src="{{= item.avatarUrl }}"></image>
  19. <text class="listItemName" value="{{= item.nickname}}"></text>
  20. </view>
  21. <text class="listItemScore" value="{{= item.rankScore}} 分"></text>
  22. </view>
  23. {{~}}
  24. </scrollview>
  25. <text class="listTips" value="仅展示前 {{= it.data.length}} 位好友排名"></text>
  26. </view>
  27. </view>
  28. */
  29. // 上述模板经过模板引擎编译成版本函数,可通过 olado.github.io/doT/index.html 在线获得
  30. function anonymous(it) {
  31. var out = '<view class="container" id="main"> <view class="rankList"> <scrollview class="list"> ';
  32. var arr1 = it.data;
  33. if (arr1) {
  34. var item, index = -1,
  35. l1 = arr1.length - 1;
  36. while (index < l1) {
  37. item = arr1[index += 1];
  38. out += ' ';
  39. if (index % 2 === 1) {
  40. out += ' <view class="listItem"> ';
  41. }
  42. out += ' ';
  43. if (index % 2 === 0) {
  44. out += ' <view class="listItem"> ';
  45. }
  46. // <text class="listItemNum" value="' + (index + 1) + '"></text>
  47. //<image class="listHeadImg" src="openDataContext/render/rank1.png">
  48. out += ' <view id="listItemUserData">'+'<image class="'+(index<3?"rankTitle":"rankTitle1")+'" src="openDataContext/render/rank'+(index+1)+'.png"> </image> '+'<image class="listHeadImg" src="' + (item.avatarUrl) + '"></image> <text class="listItemName" value="' + (item.nickname) + '"></text> </view> <text class="listItemScore" value="LV.' + (item.rankScore) + '"></text> </view> ';
  49. }
  50. }
  51. out += ' </scrollview> <text class="listTips" value="仅展示前 ' + 5 + ' 位好友排名"></text> </view></view>';
  52. return out;
  53. }
  54. module.exports = anonymous;