2012-04-29 88 views
0

我正在加載itemtap上的嵌套列表。我需要加載的是一個文件夾圖像,以防其不是一個葉節點,而是一個文檔圖像以防其葉節點。使用json商店加載圖像

我認爲這樣做的一種方式是將圖像加載到json數據本身。但我不確定如何實現這一點。

截至目前我的模型只包含一個字符串數據。我將如何加載圖像數據在thr?

//Defining a data structure for the Nested List 
Ext.define('InfoImage.model.nestedListModel', { 
    extend: 'Ext.data.Model', 

    config:{ 
    fullscreen:'true', 
    title:'Work Items Task 1', 
    ui:'normal', 
    cls:'nestedlistCls', 
    xtype:'nestedList', 
    // displayField : 'text', 
    store:'nestedListStore'/*, 
    getItemTextTpl: function() { 
     var tplConstructor = '{text}' + 
      '<tpl if="model === \'folder\'">'+ 
       '<img src="resources/images/refresh.png" >' 
       '</img>' + 
      '</tpl>'; 
     return tplConstructor; 
    }*/ 
    // itemTpl:'<div><img src="resources/images/refresh.png" > </img>{text}</div>'*/ 


} 
}); 

和我的JSON數據的代碼是:

{ 
    "items":[ 

     { 
     "text":"1.1", 
     "folder":"resources/images/refresh.png", 
     "items":[ 
      { 
       "text":"1.1.1", 
       "items":[ 
        { 
         "text":"1.a", 
         "leaf":true 
        }] 
      } 
     ] 

    }, 


     { 
      "text":"1.2", 
      "items":[ 
       { 
        "text":"1.2.1", 
        "leaf":true 
       } 
      ] 

     }, 
     { 
      "text":"1.3", 
      "items":[ 
       { 
        "text":"1.3.1", 
        "leaf":true 
       } 
      ] 

     } 
    ] 

} 

任何幫助表示讚賞。

在此先感謝。

+0

json文件基本上只是一個文本文件,我認爲你應該只讀取圖像'src'並將其保存爲普通字符串。如果是這樣,那很容易做到,那是你需要的嗎? – 2012-04-29 06:34:59

+0

我需要的是非常簡單的。我只需要2張圖片。當它不是一個葉節點,而是另一個與葉節點一起加載時,一個被加載到列表中。任何想法如何我可以實現這一目標? – Khush 2012-04-29 07:24:31

+0

似乎你可能想要使用這兩個事件:'itemtap'和'leafitemtap' – 2012-04-29 07:51:18

回答

0

首先,這可能是你一個很好的參考:Nested List not loading in sencha

那麼下面JSON將滿足您的需求(假設你已經在你的模型中定義img_src領域也一樣)

items: [ 
{ 
    text: 'not_leaf', 
    img_src: 'your_link_1', 
     items: [ 
     { text: 'leaf_1', img_src: 'your_link_2', leaf: true }, 
     { text: 'leaf_2', img_src: 'your_link_3', leaf: true } 
     ] 
    } 
] 

然後Sencha Touch會自動加載您所有的圖片來源,您可以隨心所欲地做任何事情。

注意:如果你想要做的就是聽&處理事件,您Ext.NestedList

希望這有助於使用itemtapleafitemtap事件。

+0

我試過了。我正在粘貼我在這裏嘗試的代碼。它還沒有工作。 – Khush 2012-04-29 09:04:34

+0

你得到了什麼錯誤? – 2012-04-29 09:25:34

+0

我正在獲取圖像在列表中的路徑,而沒有其他東西。 – Khush 2012-04-29 09:28:53