2011-02-16 4 views
1

나는 senchatouch에 문제가 있으며이 XML을 해독해야합니다. Product-id 특성, ProductMime URL 및 기타 컬렉션을 얻을 수있는 솔루션을 찾을 수 없습니다.Sencha Touch XML

<ProductCollection> 
<Product id="5"> 
<vendorProductId>123</vendorProductId> 
<ean>0</ean> 
<stock>no</stock> 
<name>test</name><nameShort> 
</nameShort> 
<description>description</description> 
<descriptionShort>descriptionShort</descriptionShort> 
<deliveryScope></deliveryScope> 
<price>89</price> 
<priceTax>0</priceTax> 
<priceGross>89</priceGross> 
<productCurrency>0</productCurrency> 
<ProductMimeCollection> 
    <ProductMime url="1.JPG" mimeType=""/> 
    <ProductMime url="1.JPG" mimeType=""/> 
    <ProductMime url="1.JPG" mimeType=""/> 
    <ProductMime url="1.JPG" mimeType=""/> 
    <ProductMime url="1" mimeType=""/> 
</ProductMimeCollection> 
<ProductReviewCollection rating="5" reviews="1"> 
    <ProductReview id="1"> 
    <active>1</active> 
    <customerId>2</customerId> 
    <dateCreated/> 
    <productId>5</productId> 
    <review>Reviewtext</review> 
    <shopId/> 
    <userEmail></userEmail> 
    <userName></userName> 
    <userRating>5</userRating> 
    </ProductReview> 
</ProductReviewCollection> 
<CrossSellingCollection> 
    <Product id="13"></Product> 
</CrossSellingCollection> 
</Product> 

</ProductCollection> 

당신이 속성과 요소를 가져 오는 방법에 대해 저를 보여줄 수 ... 이 있었다 내 방식대로 작동하지 않았다 :

Ext.regModel('Products', { 
    fields: ['vendorProductId', 'ean', 'stock', {name: 'ProductMime', convert: (function(){ 
      var reader2 = new Ext.data.XmlReader({ 
       record: '> url', 
       fields: [ 
        {name: 'url', mapping: '@url'} 
       ] 
      }); 
      return function(v, n) { 
       return reader2.readRecords(n).records; 
      }; 
     });} 
] 
}); 

var store = new Ext.data.Store({ 
    model: 'Products', 
    autoLoad:true, 
    proxy: { 
     type: 'ajax', 
     url : 'ajax/topten.xml', 
     reader: { 
    type : 'xml', 
    root : 'ProductCollection', 
    record: 'Product' 
    } 
    } 

당신의 도움이 나에게

감사를 도와주세요 !! !!

답변

4

속성을 가져 오는 것이 무슨 뜻인지 알지 못하기 때문에 대신에 그 속성을 가져 오는 방법을 알려 드리겠습니다. 지. DataView를 :

<!DOCTYPE html> 
<html> 
    <head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"> 
     <title>Stackoverflow Example</title> 
     <script src="../sencha-touch-debug.js" type="text/javascript"> 
     </script> 
     <link href="../resources/css/sencha-touch.css" rel="stylesheet" type="text/css"> 
     <script type="text/javascript"> 
      new Ext.Application({ 
       name: 'stackoverflow', 
       launch: function(){ 
        Ext.regModel('Products', { 
         fields: ['vendorProductId', 'ean', 'stock', { 
          name: 'ProductMime', 
          convert: (function(){ 
           var reader2 = new Ext.data.XmlReader({ 
            record: '> url', 
            fields: [ 
            { 
             name: 'url', 
             mapping: '@url' 
            }] 
           }); 
           return function(v, n) { 
            return reader2.readRecords(n).records; 
           }; 
          }) 
         }] 
        }); 

        this.stores.products = new Ext.data.Store({ 
         model: 'Products', 
         autoLoad:true, 
         proxy: { 
          type: 'ajax', 
          url : 'data.xml', 
          reader: { 
           type : 'xml', 
           root : 'ProductCollection', 
           record: 'Product' 
          } 
         } 
        }); 
       var productTpl = new Ext.XTemplate(
        '<tpl for=".">', 
         '<div class="product-wrap" id="{vendorProductId}">', 
         '<div class="product-ean">{ean}</div>', 
         '<div class="product-stock">{stock}</div>', 
        '</tpl>' 
       );  
       new Ext.Panel({ 
        fullscreen: true, 
        items: new Ext.DataView({ 
         store: this.stores.products, 
         tpl: productTpl, 
         itemSelector: 'product-selected' 
         //other config goes here 
        }) 
       }); 
      } 
     });   
     </script> 
    </head> 
    <body> 
    </body> 
</html> 

희망이 당신을 도울 수 있습니다 :)