Ohm-Management - Projektarbeit B-ME
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

home.js 2.1KB

5 years ago
5 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. const HomeRouter = {
  2. template: `
  3. <div id="om-msg-cards">
  4. <MsgCard
  5. v-for="id in messagelist.slice().reverse()"
  6. :key="id"
  7. :msg="messages[id] || {}"
  8. ></MsgCard>
  9. </div>`,
  10. data: function () {
  11. return {
  12. messagelist: _messagelist,
  13. messages: _messages,
  14. };
  15. },
  16. methods: {
  17. /*refresh_messages: function () {
  18. _messages.push({ //////// alt
  19. id: 42,
  20. subject: "xxx",
  21. message: "warum habt ihr auch so viel",
  22. user: "nobody",
  23. tags: "foo"
  24. });
  25. },*/
  26. list_messages: function () {
  27. $.ajax({url: "api/ids", method: "GET"})
  28. .done(jd => {
  29. // NICHT SO wg. Vue: _messagelist = jd;
  30. _messagelist.splice(0, _messagelist.length);
  31. _messagelist.push.apply(_messagelist, jd);
  32. console.log("jd: "+jd);
  33. for (var e in jd) {
  34. if (!_messages[jd[e]]) {
  35. get_insert_message(jd[e]);
  36. }
  37. }
  38. }).fail(function (e, f, g) {
  39. console.log("err: " + e + f + g);
  40. });
  41. }
  42. },
  43. mounted: function () {
  44. this.list_messages();
  45. //this.refresh_messages();
  46. }
  47. };
  48. function get_insert_message(id) {
  49. $.ajax({ url: "api/msg/"+id, method: "GET" }).done(function (msg) {
  50. Vue.set(_messages, id, msg);
  51. }).fail(function (e, f, g) {
  52. console.log("cannot load " + id + ".json: " + e + f + g);
  53. })
  54. }
  55. /*$(document).ready(function () {
  56. console.log("egal");
  57. $.get('list.json').done(function (jd) {
  58. // _messagelist = jd;
  59. _messagelist.splice(0, _messagelist.length);
  60. _messagelist.push.apply(_messagelist, jd);
  61. console.log("egal2");
  62. //$('#xxx').text(jd[0]);
  63. for (var e in jd) {
  64. if (!_messages[jd[e]]) {
  65. get_insert_message(jd[e]);
  66. }
  67. }
  68. }).fail(function (e, f, g) {
  69. console.log("egal3: " + e + f + g);
  70. });
  71. });*/