2012-02-02 75 views
0

我正在使用Sencha Touch編寫應用程序。所以我讀了一個XML文件並將數據放在列表視圖中。不幸的是,我的應用程序不顯示任何列表項。我在控制檯日誌中沒有錯誤,並且根據文檔完成了所有工作。Sencha Touch不顯示XML數據

app.js:

FRANF = new Ext.Application({ 
name: 'FRANF', 
useLoadMask: true, 
launch: function() { 

    FRANF.homescreenList = new Ext.List({ 
     store: FRANF.ListStore, 
     itemTpl: '<div>{id} {name}</div>' 
    }); 

    FRANF.homescreenListToolbar = new Ext.Toolbar({ 
     id: 'homescreenToolbar', 
     title: 'FRA NF' 
    }); 

    FRANF.homescreenListContainer = new Ext.Panel({ 
     id : 'itemListContainer', 
     layout : 'fit', 
     html: 'This is the notes list container', 
     dockedItems: [FRANF.homescreenListToolbar], 
     items: [FRANF.homescreenList]  
    }); 

    FRANF.viewport = new Ext.Panel({ 
     fullscreen : true, 
     layout : 'card', 
     cardAnimation : 'slide', 
     items: [FRANF.homescreenListContainer] 
    });  
} 
}); 

index.js:

Ext.regModel('Contact', { 
    fields: ['id', 'name'] 
}); 

FRANF.ListStore = new Ext.data.TreeStore({ 
    model: 'Contact', 
    autoLoad: true, 
    proxy: { 
     type: 'ajax', 
     url : 'homescreen.xml', 
     reader: { 
      type: 'xml', 
      root: 'items', 
      record: 'item' 
     } 
    } 
}); 

XML:

<?xml version="1.0" encoding="UTF-8" ?> 
<items> 
    <item> 
     <id>main-contacts</id> 
     <name>Kontakte FRA NF</name> 
    </item> 
    <item> 
     <id>important-numbers</id> 
     <name>Lufthansa-Nummern A-Z</name> 
    </item> 
    <item> 
     <id>who-does-what</id> 
     <name>Was finde ich wo?</name> 
    </item> 
</items> 

錯誤控制檯說,XML文件加載正確。

你可以看到我的測試應用程序的位置:My Sencha Touch App

回答

3

您的鏈接不包含您提供的代碼。在您使用此xml文件的鏈接中:

<?xml version="1.0" encoding="UTF-8"?> 
<item> 
    <mail>1</mail> 
    <name>Ed Spencer</name> 
</item> 
<item> 
    <mail>2</mail> 
    <name>Abe Elias</name> 
</item> 

您可以看到的是無效的。嘗試一個元素的根目錄下將它們分組,例如「項目」,即:

<?xml version="1.0" encoding="UTF-8"?> 
<items> 
    <item> 
     <mail>1</mail> 
     <name>Ed Spencer</name> 
    </item> 
    <item> 
     <mail>2</mail> 
     <name>Abe Elias</name> 
    </item> 
</items> 

那麼什麼是你真正的問題是這一行:

franf.homescreenList = new Ext.List({ 
      id: 'homescreenitems', 
      store: franf.homescreenItemsStore, 
      grouped: true,      // <- this Line 
      itemTpl: '<div class="item">{mail} {name}</div>' 
     }); 

你看你的分組列表中的項目,但你不提供如何對它們進行分組的度量。評論它,你會得到運行的應用程序。

還可以修改你的代理服務器的讀者是這樣的:

reader: { 
      type: 'xml', 
      record: 'item', 
      root: 'items' 
     } 

爲了讓他們分組檢查這個http://docs.sencha.com/touch/1-1/#!/api/Ext.List你比如有如何分組的項目。

Btw Sencha Touch 2現在處於測試階段,所以我建議使用它 - 學習而不是1.1。

這是你的整個工作代碼:

franf = new Ext.Application({ 
    name: 'franf', 
    useLoadMask: true, 
    launch: function() { 

     franf.homescreenList = new Ext.List({ 
      id: 'homescreenitems', 
      store: franf.homescreenItemsStore, 
      // grouped: true, 
      itemTpl: '<div class="item">{mail} {name}</div>' 
     }); 

     // Header Toolbar erzeugen 
     franf.homescreenListToolbar = new Ext.Toolbar({ 
      id: 'homescreenToolbar', 
      title: 'FRA NF' 
     }); 

     // Fullscreen Panel erzeugen 
     franf.homescreenListContainer = new Ext.Panel({ 
      id : 'itemListContainer', 
      fullscreen: true, 
      layout : 'fit', 
      dockedItems: [franf.homescreenListToolbar], 
      items: [franf.homescreenList]  
     }); 
    } 
}); 

Ext.regModel('Items', { 
    fields: ['mail', 'name'] 
}); 

franf.homescreenItemsStore = new Ext.data.Store({ 
    model: 'Items', 
    autoLoad: true, 
    proxy: { 
     type: 'ajax', 
     url : 'homescreen.xml', 
     reader: { 
      type: 'xml', 
      record: 'item', 
      root: 'items' 
     } 
    }, 
}); 
+1

沒有答案比這更好。你應得的+50。 – riship89 2012-02-07 07:55:32

+0

嘿,請參閱此... http://stackoverflow.com/questions/9563417/how-to-consume-soap-web-service-in-sencha-touch。 並嘗試回答它... – himanshu 2012-03-06 11:34:36

+0

停止垃圾郵件到處! – ilija139 2012-03-06 18:07:48

0

我覺得你的列表需要綁定到一個Ext.data.Store不是TreeStore。但是NestedList可以和TreeStore一起工作。

+0

不幸的是,我已經試過了。但是謝謝你的提示! – Slevin 2012-02-05 10:38:03

+0

您發佈的鏈接中的代碼與問題中的內容有點不同。我在jsfiddle中玩過它,我認爲這個代碼的問題在於xml無效,因此responseXML爲空。如果連接到sencha touch的調試版本而不是縮小版本,它也會更容易調試。 http://dev.sencha.com/deploy/touch/sencha-touch-debug.js – 2012-02-05 22:56:30