ExtJS使一个组合项目不同
ExtJS make one combo item different
也许有人可以给一些想法,如何将项目添加到组合框下拉框的末尾,并使其"不同",例如在它之前放置分隔符或使其加粗。Combobox使用排序(按名称)存储,并且在加载时添加了我想要不同的项目。
Ext.define('Plugin.workspace.store.FavouriteCarStore', {
extend : 'Plugin.workspace.store.CarStore',
alias : 'store.favouritecar',
filters : [{
property : 'favorite',
value : true
}],
listeners : {
load : function(store) {
var rec = {
id : 'showAll',
name : 'Show All',
favorite : true
};
store.add(rec);
}
}
});
组合使用这个存储:
tbar : [{
xtype : 'combo',
width : 200,
editable: false,
store : {
type : 'favouritecar'
},
bind : {
value : '{workspace}'
},
tpl : '<ul class="x-list-plain"><tpl for="."><li role="option" class="x-boundlist-item">{name}</li></tpl></ul>',
displayTpl : '<tpl for=".">{name}</tpl>',
listeners : {
'select' : 'onSelectWorkspace'
}
}].
这段代码添加了一个item,它看起来和其他item一样,并根据排序来放置它。
我使用5.1 ExtJS。
编辑:将项目添加到列表末尾的解决方案
sorters : [{
sorterFn : function(rec1, rec2) {
if (rec1.id != 'showAll' && rec2.id != 'showAll') {
return ((rec1.get('name') > rec2.get('name')) ? 1 : (rec1.get('name') === rec2.get('name') ? 0 : -1));
} else {
return ((rec1.id == 'showAll') ? 1 : -1);
}
}
}],
方法1
在连击的listConfig
上使用自定义的cls
:
listConfig: {
cls: 'thisComboMakesLastItemDifferent'
},
然后使用CSS使最后一项不同:
.thisComboMakesLastItemDifferent li:last-child {
color: red;
font-weight: bold;
}
方法2
既然你用favorite: true
标记你的"不同"项目,你可以在模板中编码:
tpl: '<tpl for="."><li role="option" class="x-boundlist-item favorite-{favorite}">{name}</li></tpl>',
然后,再次使用CSS:
.favorite-true:before {
content: 'FAV: '
}
注意,第一种方法的重点是使最后一个项不同,而不管是什么项。第二种方法使特定的项不同(您需要额外的逻辑来确保它是最后一个;你已经有一个了)。
查看两个方法的实际操作:https://fiddle.sencha.com/#fiddle/sdj
也许您可以使用store.insert(store.indexOf(store.last()) index, rec)
或store.insert(store.count() - 1, rec)
?
load : function(store) {
somewhere.static.setShowAllAsLastRecordOfStore(store);
}
filterchange(store, filters, eOpts) {
somewhere.static.setShowAllAsLastRecordOfStore(store);
}
sort(store, eOpts) {
somewhere.static.setShowAllAsLastRecordOfStore(store);
}
setShowAllAsLastRecordOfStore: function(store) {
var rec = {
id : 'showAll',
name : 'Show All',
favorite : true
};
store.remove(store.findRecord('id', 'showAll'));
store.insert(store.indexOf(store.last()) index, rec);
// or
store.insert(store.count() - 1, rec);
}
相关文章:
- 拉力赛:有没有一种简单的方法来获取项目组合项目下的所有用户故事
- JavaScript算法,提供每种可能的项目组合,并将它们存储在数组中
- 根据组合框中选定的默认项目加载排列,并在更改选定项目时重新加载(淘汰)
- 当表单控件选项具有多个参数时,如何在组合框中填充所选项目
- 识别项目组合的最快方法
- Vaadin组合框:在输入时加载项目
- 剑道网格:如何在与Angular一起使用时从组合框单元格模板中获取所选项目
- 对同一页面上的多个项目使用剑道UI翻转效果/组合效果
- 按项目组合项类型筛选
- 如何在 ExtJS5 中网格编辑器组合的当前记录中添加项目
- 如何根据另一个组合框的选定项目从数据库填充组合框中的项目
- EXT JS :如何有条件地隐藏组合框中的项目
- 如何以任何给定的方式在组合框中显示项目
- 如何从组合框中获取所选项目
- 如何正确地缩小/组合网页项目中的CSS/JS与url重写
- 分享facebook项目组合
- 在PaperJS中,可以将多个项目组合在一起,使它们作为一个项目移动
- 将项目附加到组合框中
- 使用组合框项目值自动链接到href
- ExtJS使一个组合项目不同