2011-11-17 99 views
0

我打电话跟我煎茶触摸手机应用程序的网络服务:诊断空店负载

Ext.regModel('BaseResponse', { 
    idProperty: 'ResponseTime', 
    fields: [ 
     { name: 'ErrorMessage', type: 'string' }, 
     { name: 'ResponseTime', type: 'date', dateFormat: 'c' },  
     { name: 'StatusCode', type: 'string' }, 
     { name: 'Success', type: 'string' } 

    ] 
}); 


var declineResult = new Ext.regStore('declineResult', 
    { 
      model: 'BaseResponse', 
      proxy : { 
      type : 'ajax', 
      dataType: "json", 
      url : App.BaseURL + '/SetJobResponse/' + options.jobId + '/' + STCID +'/' + options.OJSStatusID + '/' + device.uuid, 
      reader: new Ext.data.JsonReader ({ 
       type: 'json' 
       }) 
     }, 
      listeners: 
      { 
      'load': function(store,records,successful) 
       {       
       alert(records.length); 
       //alert('response message:' + Ext.StoreMgr.get("declineResult").getAt(0).ErrorMessage); 
       }, 

      'loadexception': function() 
      { 
       alert('There was a load exception'); 
      } 
      } 
    }); 

    Ext.StoreMgr.get("declineResult").load();  

这里的JSON由URL返回如果我只是浏览到它:

{"ErrorMessage":"You are not authorised","ResponseTime":"\/Date(1321447985287)\/","StatusCode":401,"Success":false} 

然而即使我的加载事件显示Successful = true,记录也是空的(长度为0)。 异常事件未被触发。 如何进一步诊断?我使用Sencha Touch和带有Android模拟器的Phonegap使用Eclipse。有什么方法可以查看返回的内容吗?

回答

0

我发现,煎茶1.x中似乎并没有能够处理这些回应:

  • JSON数据的一个空数组
  • 返回而不是数组的单个对象

我最终做的是使用Ext.override对这些服务器响应实施适当的客户端响应。

得到这个工作,你必须调试(使用煎茶调试库和地方断点在那里,用你的JavaScript调试器),看看您的应用程序崩溃。然后,您会在崩溃的调用堆栈中找到Ext.data.Reader。 下一步是重写像ExtractData由和readRecords其成员函数(如果需要像空指针检查)来实现适当的功能。

相关链接: http://docs.sencha.com/touch/1-1/source/Reader.html#Ext-data-Reader

0

我结束了它周围越来越通过消除对商店的需要:

Ext.regController('RequestDetailsC', { 
    userSettings: function() { 
    console.log('reqdetails controller called.'); 
    }, 

    declineRequest: function(options) { 
     console.log('decline called.'); 

     var STCID = '8'; 

     Ext.Ajax.request({ 
      url: App.BaseURL + '/SetJobResponse/' + options.jobId + '/' + STCID +'/' + options.OJSStatusID + '/' + device.uuid, 
      method: 'GET', 
      success: function(result, request) { 
       var resultJson = Ext.decode(result.responseText); 
       alert(resultJson.ErrorMessage); 
      }, 
      failure: function(result, request) { 
       Ext.Msg.alert('Error!', 'There was a problem while loading the data...'); 
      } 
     });    

    }