2012-11-19 33 views
6
this.loadSmt = function(argPanel) 
{ 
    this.store1 = new Ext.data.JsonStore({ 
     url    : 'URL1', 
     totalProperty : 'total', 
     successProperty : 'success', 
     root   : 'root1', 
     fields   : [ 
          {name: 'data1'}, 
          {name: 'data2'} 
         ] 
    }); 

    this.store2 = new Ext.data.JsonStore({ 
     url    : 'URL2', 
     totalProperty : 'total', 
     successProperty : 'success', 
     root   : 'root2', 
     fields   : [ 
          {name: 'data21'}, 
          {name: 'data22'}, 
          {name: 'data23'}, 
          {name: 'data24'}, 
          {name: 'data25'} 
         ] 
    }); 

    this.store1.on('beforeload', function() { 
     this.store1.baseParams = { 
      argID: myID 
     }; 
    }, this); 

    this.store2.load({ 
     callback : function() { 
      var graphOwner = argPanel; 
      var graphDataArr = []; 
      var i = 0; 
      this.data.each(function(item, index, totalItems) { 
       var data1 = item.data['data1']; 
        var data2 = item.data['data2']; 

        // create arraystore data for graph 
        var tempArr = new Array(); 
        tempArr.push(data1); 
        tempArr.push(data2); 
        graphDataArr[i] = tempArr; 
        i++; 
      }); 


      this.GraphPanel = this.getMyGraph(graphDataArr); 

     } 
    }, this); 
}; 

this.getMyGraph = function(argGraphValue) 
{ 
    // do something 
} 

khi tôi chạy mã này tôi nhận đượcLàm thế nào để sử dụng phạm vi chức năng lưu trữ tải trong ExtJS

TypeError: this.getMyGraph is not a function

lỗi, khi tôi sử dụng

this.data.each

chức năng trong cửa hàng gọi lại, tôi có thể' t sử dụng

this.getMyGraph

chức năng. Tôi nghĩ rằng đây là một vấn đề phạm vi, làm thế nào tôi có thể vượt qua phạm vi như tham số cho một chức năng hoặc làm thế nào tôi có thể sửa lỗi này?

Trả lời

7

Cách vượt qua phạm vi của bạn không đúng. Bạn cần sử dụng thông số phạm vi của các tùy chọn tải.

this.store2.load({ 
    callback : function(records, operation, success) { 
    ... 
    }, 
    scope: this 
}); 

http://docs.sencha.com/ext-js/4-1/#!/api/Ext.data.Store-method-load

+0

tôi thay đổi mã của tôi như bạn thấy. Bây giờ tôi nhận được 'TypeError: this.data là undefined' lỗi. – vtokmak

+2

Thay đổi chữ ký gọi lại thành 'hàm gọi lại: hàm (bản ghi, thao tác, thành công)' và sử dụng bản ghi this.data thay vì – Damask

+0

nó hoạt động. thx rất nhiều @Prodigy – vtokmak

Các vấn đề liên quan