PageRenderTime 51ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/static/js/global.js

https://bitbucket.org/chepy/iosappcatcher
JavaScript | 160 lines | 71 code | 40 blank | 49 comment | 0 complexity | 57cff0ac930c605b8031c70a78595ca4 MD5 | raw file
  1. //var general_var;
  2. $(function(){
  3. /**
  4. * AppInfo Model
  5. *
  6. * 传入app在itunes的网址, 获取app详细信息对象
  7. * var app_info = AppInfoModel({ url:app_url});
  8. */
  9. var AppInfoModel = Backbone.Model.extend({
  10. defaults: {
  11. url: '~url~',
  12. name: '~name~'
  13. },
  14. initialize: function(){
  15. // 通过网址读取app信息,并放入对象属性
  16. this.remote_read( this.get('url') );
  17. },
  18. remote_read_url : '/api/app/get?id=',
  19. remote_read: function( app_id ){
  20. //_.bindAll(this, 'defaults');
  21. _this = this; // 解决ajax中失去this的问题
  22. $.ajax( {
  23. type: 'get',
  24. dataType:'json',
  25. url: _this.remote_read_url + app_id,
  26. //async:false, // 同步与异步
  27. beforeSend: function(){
  28. //alert('loading show');
  29. // Loading显示
  30. },
  31. complete:function(){
  32. //alert('loading close');
  33. // Loading 隐藏
  34. },
  35. success: function(json_data) {
  36. // 设置model数据
  37. _this.set( {
  38. name: json_data.app_name,
  39. intro: json_data.app_intro
  40. });
  41. //alert( data );
  42. alert( _this.get('name') );
  43. }
  44. }
  45. //_this.remote_read_url + app_id, function(data){
  46. //alert( _this.defaults );
  47. //alert( _this.get('url') );
  48. // 完成读取,设置属性
  49. );
  50. }
  51. });
  52. /**
  53. * AppInfo List
  54. */
  55. var AppInfoCollection = Backbone.Collection.extend({
  56. model: AppInfoModel
  57. });
  58. /**
  59. * Body View 整个页面
  60. */
  61. var BodyView = Backbone.View.extend({
  62. el: $('body'),
  63. events: {
  64. 'click button.button_get_app' : 'button_get_app_click'
  65. },
  66. initialize: function(){
  67. _.bindAll(this, 'button_get_app_click');
  68. // AppInfoCollection
  69. //this.app_info_collection = new AppInfoCollection;
  70. //this.app_info_collection.bind( 'add', this.app_info_list_view.append ); // 当数据collection增加时,视图也相应的增加app显示
  71. },
  72. button_get_app_click: function(){
  73. var app_info_model = new AppInfoModel({
  74. url : $('.input_app_id').val()
  75. });
  76. //alert( app_info_model.url() );
  77. //$('.input_app_id').
  78. //$.get('/', function(data){
  79. // AppInfo model-collection 增加
  80. // AppInfoListView 增加 AppInfoView
  81. // 显示AppInfoListView
  82. // alert(data);
  83. //});
  84. return false;
  85. }
  86. });
  87. /**
  88. * 需要传入model
  89. */
  90. var AppInfoView = Backbone.View.extend({
  91. tagName: 'li',
  92. initialize: function(){
  93. _.bindAll(this, 'render');
  94. },
  95. render: function(){
  96. $(this.el).html('<span>' + '</span>');
  97. }
  98. });
  99. /**
  100. * 路由器
  101. */
  102. var PageRouter = Backbone.Router.extend({
  103. initialize: function(){
  104. // 全个页面的视图
  105. var body_view = new BodyView;
  106. },
  107. routes: {
  108. '*actions': 'defaultRoute'
  109. },
  110. defaultRoute:function(){
  111. }
  112. });
  113. var page_router = new PageRouter();
  114. Backbone.history.start();
  115. // 按钮绑定
  116. //$('.button_get_app').click(function(){
  117. // alert( $('.input_app_id').val() );
  118. // return false;
  119. //});
  120. });