2012-02-12 3 views
0

ExtJS4 Store를 사용하여 Json 데이터를 반환하는 Javascript 함수를 실행하려고합니다. getMyJsonData를 호출하여 데이터를 상점에로드하십시오. DOCO을 통해 트롤 어업을ExtJS4 Ext.data.Store 함수에서 데이터로드

function getMyJsonData() { 
    var myjson = {... }; 
    return myjson; 

} 

, 내가 데이터를로드하기위한 콜백 함수를 정의 할 수있는 방법을 찾을 수없는, 내가 찾은 모든 이미 정의 된 데이터 객체를로드하는 메모리 저장했다.

대신 함수를 호출 할 수 있습니까?

Ext.define('perhoo.store.Users', 
     { 
      extend: 'Ext.data.Store', 
      model: 'perhoo.model.User', 
      autoLoad: true, 


       data : { 
       users: [ 
        { id: 1, name: 'joe44', email: '[email protected]'}, 
        { id: 2, name: 'bloggs44', email: '[email protected]'} 
        ] 
      }, 

      proxy: { 
       type: 'memory', 
       data: this.data, 
       reader: { 
        type : 'json', 
        root : 'users' 
       } 
      } 

편집

내가 링크드 인 API를 실행하려는 때문에 함수가 호출 할 이유. 그리고 (이 크로스 도메인의로) 내가 가야로 일을 10 배 더 복잡하게 내선 JSONP 프록시를 통과 링크드 인 인증 등 등 (나는 아직 그것을하는 방법을 알고하지 않는)

즉 VAR 다음 mydata = 널 (null) ; 실행될 때

var myStore = Ext.create('Ext.data.Store', { 
    model: 'User', 
    proxy: { 
     type: 'ajax', 
     url : '/users.json', 
     reader: { 
      type: 'json', 
      root: 'users' 
     } 
    }, 
    autoLoad: true 
}); 

는 그것이 url, /users.json로부터 데이터를 판독하고, 그 자체로 저장할 :

function onLinkedInAuth() { 
    // Linked in api to find connections 
    IN.API.Connections("me").result(function(result) { 

     mydata = result; 
    }); 

} 
+0

당신은 무엇을 의미합니까? 전 아약스를 통해 데이터를 가져 오시겠습니까? – Hadas

+0

함수를 호출하려는 이유는 LinkedIn API를 실행하려고하기 때문입니다. 그리고 Ext JSONP 프록시 (크로스 도메인)를 사용하면 10 배 이상 복잡해집니다. 링크드 인 인증 등을 받아야합니다. (이 방법은 아직 모릅니다) – portoalet

+0

사용자 데이터를 사용해 보셨나요? yourfunction) 또는 비슷한 것이 있습니까? – Hadas

답변

0

데이터를로드하기 위해 프록시를 사용 ExtJS4 스토어는 아래 확인.

//this is the model we will be using in the store 
Ext.define('User', { 
    extend: 'Ext.data.Model', 
    fields: [ 
     {name: 'id', type: 'int'}, 
     {name: 'name', type: 'string'}, 
     {name: 'phone', type: 'string', mapping: 'phoneNumber'} 
    ] 
}); 

//this data does not line up to our model fields - the phone field is called phoneNumber 
var data = { 
    users: [ 
     { 
      id: 1, 
      name: 'Ed Spencer', 
      phoneNumber: '555 1234' 
     }, 
     { 
      id: 2, 
      name: 'Abe Elias', 
      phoneNumber: '666 1234' 
     } 
    ] 
}; 

//note how we set the 'root' in the reader to match the data structure above 
var store = Ext.create('Ext.data.Store', { 
    autoLoad: true, 
    model: 'User', 
    data : data, 
    proxy: { 
     type: 'memory', 
     reader: { 
      type: 'json', 
      root: 'users' 
     } 
    } 
}); 

을 그리고 당신은 쉽게 당신이 원하는 때 동작을 변경할 setProxy을 사용할 수 있습니다 당신은 자신의 데이터를 직접 처리 및 저장에로드하려는 경우

또한, 아래 확인할 수 있습니다.

링크 :

+0

LinkedIn API를 실행하고 싶기 때문에 함수를 호출해야하는 이유가 있습니다. 그리고 Ext JSONP Proxy (크로스 도메인으로)를 사용하면 LinkedIn 인증 등을 받아야하기 때문에 10 배 더 복잡해집니다 (아직 어떻게하는지 모릅니다). 그리고 extjs4가 이것을 어떻게 할 수 있는지 보지 못했습니까? – portoalet

+1

@portoalet 제가 아는 한, 처음에는 빈 프록시를 설정하고 데이터가 준비되면 setProxy를 사용하여 빈 프록시를 잘 준비된 메모리 프록시로 바꿉니다. 또한 DirectProxy에는 데이터 요청을 완료하는 함수가있는 것 같습니다. http://docs.sencha.com/ext-js/4-0/#!/api/Ext.data.proxy.Direct – liuyanghejerry

+0

감사합니다. 나는 http://stackoverflow.com/questions/6873534/extjs4-why-when-i-use-directfn-config-in-my-store-i-need-to-specify-directcfg-m을 따라 갔고 이제는 작동한다. – portoalet