在sencha touch 里我们会给一些空间添加自定义字段。如下
Ext.define("DingCan.view.category.FoodsList", {
extend : 'Ext.DataView',
xtype : 'foodslist',
requires: ['Ext.SegmentedButton'],
config : {
title : '菜谱分类',
//viewModel就是自定义字段
viewModel:'',
store : 'foodstore',
itemSelector : 'div.node',
itemTpl : '<div class="img-desc"><img width="100" height="100" src="{thumbsrc}" alt=""/><cite>{price}元/份</cite>{ordernum}</div>',
masked : {
xtype : 'loadmask',
message : '数据加载中.'
}
},
initialize : function() {
//console.log('打印foodlist initial');
//console.log(this.viewModel);
this.callParent();
},
beforeInitialize : function() {
//this.foodlistEl = this.down('#foodlist');
//首先我们需要给自定义字段赋值
this.viewModel = 'picModel';
}
})
然后我们可以通过方法去赋值,注意自定义的字段是通过.访问的。而系统定义的字段需要用.getxxx()方法访问
foodlist.viewModel = ‘picModel’
foodlist.getTitle();
foodlist.setTitle(123);