2012-04-29 86 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