Sencha touch 如何在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-
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
或添加
以手动将图像添加到旋转木马,因此只要您了解此技巧,您就可以选择合适的方式。