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.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. const HomeRouter = {
  2. template: `
  3. <div id="om-msg-cards">
  4. <MsgCard
  5. v-for="id in messagelist"
  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. for (var e in jd) {
  33. if (!_messages[jd[e]]) {
  34. get_insert_message(jd[e]);
  35. }
  36. }
  37. }).fail(function (e, f, g) {
  38. console.log("err: " + e + f + g);
  39. });
  40. }
  41. },
  42. mounted: function () {
  43. this.list_messages();
  44. //this.refresh_messages();
  45. }
  46. };
  47. function get_insert_message(id) {
  48. $.ajax({ url: "/api/msg/"+id, method: "GET" }).done(function (msg) {
  49. Vue.set(_messages, id, msg);
  50. }).fail(function (e, f, g) {
  51. console.log("cannot load " + id + ".json: " + e + f + g);
  52. })
  53. }
  54. /*$(document).ready(function () {
  55. console.log("egal");
  56. $.get('list.json').done(function (jd) {
  57. // _messagelist = jd;
  58. _messagelist.splice(0, _messagelist.length);
  59. _messagelist.push.apply(_messagelist, jd);
  60. console.log("egal2");
  61. //$('#xxx').text(jd[0]);
  62. for (var e in jd) {
  63. if (!_messages[jd[e]]) {
  64. get_insert_message(jd[e]);
  65. }
  66. }
  67. }).fail(function (e, f, g) {
  68. console.log("egal3: " + e + f + g);
  69. });
  70. });*/