Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/extjs/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sencha touch 如何在sencha touch中将图像从存储动态绑定到旋转木马_Sencha Touch_Extjs_Sencha Touch 2_Carousel - Fatal编程技术网

Sencha touch 如何在sencha touch中将图像从存储动态绑定到旋转木马

Sencha touch 如何在sencha touch中将图像从存储动态绑定到旋转木马,sencha-touch,extjs,sencha-touch-2,carousel,Sencha Touch,Extjs,Sencha Touch 2,Carousel,我在sencha touch应用程序中声明了以下商店 Ext.define('Sample.store.ImageStore', { extend: 'Ext.data.Store', config: { model: 'Sencha.model.ImageModel', data: [{ name: "cat", url: "http://bleachthemind.files.wordpress.com/2010/08/cute-bunnys-

我在sencha touch应用程序中声明了以下商店

Ext.define('Sample.store.ImageStore', {
    extend: 'Ext.data.Store',
    config: {
        model: 'Sencha.model.ImageModel',
        data: [{ name: "cat", url: "http://bleachthemind.files.wordpress.com/2010/08/cute-bunnys-domestic-animals-2785589-1024-768.jpg" },

            { name: "lion", url: "http://images1.fanpop.com/images/photos/2600000/Cheetah-Family-wild-animals-2603080-1280-1024.jpg" }
        ]
    }
});
这是我在模型中声明的代码:

Ext.define('Sample.model.ImageModel', {
    extend: 'Ext.data.Model',
    config: {

     fields:['name','url']
}
});

我很难用carousel构建一个视图,其中数据是从上面提到的存储绑定的。请告诉我如何使用carousel消费存储数据在视图中编写正确的语法

在Sencha Touch中,您无法将店铺连接到旋转木马。似乎您必须通过以下方式手动执行此操作:

yourCarousel = Ext.getCmp('your_carousel_id');
store.each(function(record){
                    yourCarousel.add({
                        html: '<img src=' + record.get('url') + '/>'
                    });
                });
yourCarousel=Ext.getCmp('your_carousel_id');
存储。每个功能(记录){
你的旋转木马({
html:'
});
});
泰姆的回答很好。 如果你想要一个更完整的例子,请看这篇漂亮的文章:

我认为它应该满足你的所有需要;)


希望这能有所帮助。

谢谢您的回复,您上面提到的代码应该放在商店中,对吗?是的,或者放在任何控制器函数中,因为您可以通过
Ext.getStore('your_store_id')
轻松获得您的商店,以及使用商店的我的视图类似于Ext.define('Sample.view.ProductsView'),{extend:'Ext.Panel',xtype:'productsview',config:{dockditems:[{xtype:'toolbar',title:'Products'}],items:[{xtype:'carousel',store:'ImageStore',}];如果您将
id:'imageCarousel'
设置为您的carousel声明,则
Ext.getStore('ImageStore')
等于
store
Ext.getCmp('imageCarousel'))
等于我上面的代码片段中的
yourCarousel
。然后你可以在任何地方编写代码。我将我的视图语法更改为此,但它不起作用。define('Sample.view.ProductsView',{extend:'Ext.Panel',xtype:'gallery',id:'imagecarousel',config:{dockditems:[{xtype:'toolbar',title:'Products'}],items:[{xtype:'carousel',store:'ImageStore',id:'imagecarousel',initComponent:store.each(函数(记录){imagecarousel.add({html:'}); }); }] });谢谢你的回复,我试着遵循同样的例子,但问题是他们的app.js文件中的代码太多了,这并不理想,我希望我的app.js文件是minimalborck的回复是一个很好的建议,如果你想构建一个扩展,你可以通过编程多次使用。顺便说一句,核心是他们使用
push
添加
以手动将图像添加到旋转木马,因此只要您了解此技巧,您就可以选择合适的方式。