simple-demo.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. /*****
  2. *
  3. * Assuming a HTML like
  4. *
  5. * <... id="test-app-1">
  6. * <... v-for="oneuser in userlist">
  7. * {{oneuser.id}} , name: {{oneuser.name}}
  8. * </...>
  9. *
  10. * </...>
  11. *
  12. */
  13. var test_vue_app = new Vue({
  14. el : "test-app-1",
  15. data : {
  16. userlist : [{id:1, name:"hello"}]
  17. }
  18. });
  19. /******************************************************************************
  20. //
  21. // To load directly from JS(jQuery)
  22. //
  23. /*****************************************************************************/
  24. function js_load_something(){
  25. var uid = 5; //for test.
  26. BasicFunction.get_data("smartUsers/list"+"?userId="+uid,
  27. /**
  28. * 下面的function是访问网络成功后的结果回调,obj 类似
  29. *
  30. * http://south.niimei.com:8866/server/smartUsers/list
  31. * {
  32. * "ret":"10000","detail":null,"field":null,"model":
  33. * {"page":1,"pageSize":15,"totalPage":1,"totalResult":15,
  34. * "list":
  35. * [
  36. * {
  37. * "uid":3,"usn":"cell_13520583918","pss":"64e604787cbf194841e7b68d7cd28786f6c9a0a3ab9f8b0a0e87cb4387ab0107",
  38. * "name":"HelloWorld","title":"","priv":"view,order,deliver,pay","state":0,"sess":"iOgxGPkFIV3JxBlBfCv",
  39. * "phone":"13520583918","schoolDistrict":null,"userExpPts":null,"userGroup":null,"userVcoin":null,"registerTime":null,
  40. * "lastLoginTime":null,"wxUnionid":null,"wxEngineid":null,"wxOpenid":null,"note":null
  41. * },
  42. * {..第二条数据..},
  43. * {..第三条数据..}
  44. * ]
  45. * }
  46. * }
  47. * @param obj
  48. */
  49. function (obj) {
  50. var parsedObj = first_parse(this, obj);
  51. if(parsedObj != null && parsedObj != undefined) {
  52. test_vue_app = parsedObj.list;
  53. } else {
  54. // error
  55. }
  56. } //end of f (obj, status)
  57. ); // end of get_data
  58. }
  59. /******************************************************************************
  60. //
  61. // To load using DataObject + DataService + Module stuff
  62. //
  63. *****************************************************************************/
  64. //Module means some component (need only to draw);
  65. var test_vue_module = new Module("nothing", "smartUsers");
  66. test_vue_module.drawData = function (data) {
  67. test_vue_app.data.userlist.pop();
  68. for(let i = 0; i < data.len(); i++) {
  69. test_vue_app.data.userlist.push(data.getSorted(i));
  70. }
  71. } ;
  72. var loader = new (function(){
  73. /* this is the main data service that is auto-updating your data*/
  74. this.userListServ = new DataObjectService("smartUsers", AUTO, "?ext=1");
  75. // Optional for setting up self-defined interval
  76. // this.userListServ.autoInterval = 300;
  77. // this.userListServ.setUpInterval();
  78. /**
  79. * load Once, as is.
  80. */
  81. this.loadOnce = function(){
  82. var list = this.userListServ.list;
  83. test_vue_module.setData(list);
  84. };
  85. /***
  86. * loadOften : to auto-load some data
  87. */
  88. this.loadOften = function(){
  89. // Binding Intervals to DataService
  90. this.userListServ.bind(function (data) {
  91. // auto call
  92. test_vue_module.setData(data);
  93. });
  94. };
  95. })();
  96. //To load once
  97. loader.loadOnce();
  98. //To auto-refresh
  99. // loader.loadOften();