2015-01-11 5 views
0

어떻게 든 여러 매장/json 요청을 같은 저장소에 포함시킬 수 있습니까? 예를 들어 Sencha Touch 2 : 같은 저장소에있는 두 개의 REST 요청

내가 JSON 객체를이 API 반환 한 그 :

http://api1.domain.com

{"name":"john"},{"name:"harry"} 

http://api2.domain.com

{"name":"peter"},{"name:"fred"} 

내가 위해 하나 개의 저장소에 API1와 API2의 결과를 병합 할 단일보기에서 처리하기 위해 모두 연결됩니다. 결과 :

{"name":"john"},{"name:"harry"},{"name":"peter"},{"name:"fred"} 

아니면 연결된하지만 동시에이 두 API를 호출 단일 뷰에 표시 할 수 없습니다 :이 가능 존 해리 피터 프레드

?

내가 더 성공이 노력하고있어 :

Ext.application({ 
    name: 'sencha', 
    views: ['Main1'], 
    models:['AdModel'], 
    stores:['AdStore1','AdStore2'], 
    launch: function() { 

    var store1Obj = Ext.getStore('AdStore1'); 
    var store2Obj = Ext.getStore('AdStore2'); 

    store1Obj.each(function(record){ 
     var copiedRecord = record.copy(); 
    store2Obj.add(copiedRecord); 
    }); 

    Ext.create('Ext.DataView', { 
     fullscreen: true, 
     store: store2Obj, 
     itemTpl: '<tpl for="."><div><strong>{name}</strong></div></tpl>' 
     }); 
    } 

}); 

답변

0

을 첫째로 당신이 storehttp://docs-origin.sencha.com/touch/2.4/2.4.1-apidocs/#!/api/Ext.data.Store-method-each

each 방법에 대한 잘못된 구문을 사용하는 것은 그 다음 함께 2 개의 다른 데이터 소스를 추가하는 간단 같은 가게에서.

Ext.application({ 
    name: 'Fiddle', 

    launch: function() { 

     // Set up a model to use in our Store 
     Ext.define("User", { 
      extend: "Ext.data.Model", 
      config: { 
       fields: [{ 
        name: "name", 
        type: "string" 
       }] 
      } 
     }); 

     // Setup the stores 
     var myStore1 = Ext.create("Ext.data.Store", { 
      model: "User", 
      data: [{ 
       "name": "john" 
      }, { 
       "name": "harry" 
      }], 
      autoLoad: true 
     }); 

     var myStore2 = Ext.create("Ext.data.Store", { 
      model: "User", 
      data: [{ 
       "name": "peter" 
      }, { 
       "name": "fred" 
      }], 
      autoLoad: true 
     }); 

     // Loop through each record of store2 adding it to store1 
     myStore2.each(function(item, index, length) { 
      myStore1.add(item); 
     }); 

     Ext.create("Ext.List", { 
      fullscreen: true, 
      store: myStore1, 
      itemTpl: "{name}" 
     }); 
    } 
}); 

데모 : https://fiddle.sencha.com/#fiddle/g6n