擴展js代碼css
1 /* 2 *list多選擴展 3 */ 4 Ext.define('ux.SimpleList', { 5 alternateClassName: 'simpleList', 6 extend: 'Ext.List', 7 xtype: 'simpleList', 8 config: { 9 editCls: 'simpleList', 10 //不加在長按時可能沒反應 11 onItemDisclosure: false, 12 //是否在多選狀態(不可更改) 13 isSimple: false, 14 //設置數據主鍵(可配置) 15 ckId: 'id', 16 //默認選擇類型,用以應對多種選擇狀況 17 defSimpleType: 0, 18 //多選時彈出菜單欄(可配置) 19 simpleToolBar: { 20 //默認位置 21 docked: 'bottom', 22 //默認標題,用以應對多種選擇狀況 23 defTitle: '刪除', 24 items: [{ 25 xtype: 'button', 26 text: '全選', 27 align: 'left', 28 //標誌是全選仍是取消全選 29 isSimple: true, 30 listeners: { 31 tap: function (button) { 32 var list = button.up('list'); 33 if (this.isSimple) { 34 this.setText('取消全選'); 35 list.selectAll(); 36 } else { 37 this.setText('全選'); 38 list.deselectAll(); 39 } 40 this.isSimple = !this.isSimple; 41 } 42 } 43 }, 44 { 45 cls: 'moreButton', 46 xtype: 'button', 47 text: '取消', 48 align: 'right', 49 listeners: { 50 tap: function (button) { 51 var list = button.up('list'); 52 //結束多選 53 list.endSimple(list); 54 } 55 } 56 }, 57 { 58 cls: 'moreButton', 59 xtype: 'button', 60 text: '肯定', 61 align: 'right', 62 listeners: { 63 tap: function (button) { 64 var list = button.up('list'); 65 var items = list.getSelection(); 66 //獲取選中項 67 var ids = []; 68 for (var i = 0, 69 item; item = items[i]; i++) { 70 ids.push(item.data[list.config.ckId]); 71 } 72 if (ids.length>0) { 73 //觸發選擇成功事件list:list自己,items:被選中的行,ids:被選中key集合,list.config.simpleType:自定義配置狀態 74 list.fireEvent('simpleSuccess', list, items, ids, list.config.simpleType); 75 //結束多選 76 list.endSimple(list); 77 } 78 } 79 } 80 }] 81 }, 82 listeners: { 83 //監控是否在多選狀態 84 itemtap: function (list, index, target, record, e) { 85 //若是在多選狀態中止後續事件的執行 86 if (this.config.isSimple) { 87 e.stopEvent(); 88 } 89 }, 90 //只要按鍵長按住就會觸發,和按鍵是否離開沒有關係 91 itemtaphold: function (list, index, target, record, e) { 92 //開始多選 93 this.beginSimple(); 94 } 95 } 96 }, 97 //獲取多選邊欄 98 getSimpleToolBar: function () { 99 var simpleToolBar = Ext.create('Ext.TitleBar', this.config.simpleToolBar); 100 return simpleToolBar; 101 }, 102 //進入多選狀態 103 beginSimple: function (simpleType, title) { 104 if (!this.config.isSimple) { 105 //取消全選 106 this.deselectAll(); 107 //進入多選模式 108 this.setMode('SIMPLE'); 109 //添加css 110 this.addCls(this.config.editCls); 111 //顯示OnItemDisclosure 112 this.setOnItemDisclosure(true); 113 //加入標記,以便在itemtap事件中進行斷定 114 this.config.isSimple = true; 115 //應對多種選擇需求 116 if (simpleType) { 117 this.config.simpleType = simpleType; 118 } else { 119 this.config.simpleType = this.config.defSimpleType; 120 } 121 //改變標題 122 if (title) { 123 this.config.simpleToolBar.title = title; 124 } else { 125 this.config.simpleToolBar.title = this.config.simpleToolBar.defTitle; 126 } 127 //添加多選邊欄 128 this.add(this.getSimpleToolBar()); 129 } 130 }, 131 //結束多選模式 132 endSimple: function () { 133 var titlebar = this.down('titlebar'); 134 if (titlebar) { 135 //移除多選邊欄 136 titlebar.hide(); 137 titlebar.destroy(); 138 //取消全選 139 this.deselectAll(); 140 //進入單選模式 141 this.setMode('SINGLE'); 142 //移除css 143 this.removeCls(this.config.editCls); 144 //隱藏OnItemDisclosure 145 this.setOnItemDisclosure(false); 146 //加入標記,以便在itemtap事件中進行斷定 147 this.config.isSimple = false; 148 } 149 }, 150 //更新OnItemDisclosure須要 151 updateOnItemDisclosure: function (newConfig, oldConfig) { 152 if (oldConfig == null) { 153 return; 154 } 155 var items = this.listItems; 156 for (var i = 0, 157 ln = items.length; i < ln; i++) { 158 var dItem = items[i].getDisclosure(); 159 newConfig === false ? dItem.hide() : dItem.show(); 160 } 161 } 162 });
須要加入的cssweb
1 .simpleList .x-list-disclosure { 2 -webkit-mask-size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V4zkTHHEqSfZSzr+94V0mbzKUF1GkSWknG5QktGyoj7qBdVeZo2S1Ch2yUNXOMVUcEJyrcQjOeP4vzQCu9BpBtOck5T70HybN4w1iJcR7ouem9QPjhfG+On7EBPUNrKhrYLWp7+FS1FCjtdKvJ6VvM/Q9o2uWC1AHq60QB6hELh0voJ+im6iHReF+FZwe5HP/g8lrXNzuEfeeFu9C9Kg8nSrr9lBZ9ljK/v37xjL5qRFSytf3K15KXy9EH0D/JN3ui2Qj1rC5AAq4FnJvoDPUSNBnTnUy4YQF1maFHlCOAYuouJFN6PkWtEo+ryrH5sL2TPVi5UFXAMrfDegxrtae3ZfWh6paFFffYCx9BKZLtQo/a0YLXIhSUo3yKlAsfQ8vSBBkALtrCjxwdqbTWBY2glst9REee0Lw/ULUEZpFuOChxD1yuRybNbUV0SlAtq9SDgGFp7ushEJlhdKuqWoAzSLYOBHeidGPkc+cIztE2wA6iuCcoFtXom4Bha4f0nGmv2FqyOnoaFscFG9rsfQusYq0T2G8qayASrbdEdOlfR/TJ72AzAaHla5/QD9BnVCucvfK/fjZXtx8WzZneu/+WBf53XOb0G6XetHjQXyfv2vKLyH7qLLqMhJn5DOW5PLmBZDfRUilloGUoD/ovvXgIrT4/rkxt4XK0fw+TtYxhT6iEt4FK7L8D4locDFqnUXSadh78Bx5bEl2CLG+8AAAAASUVORK5CYII=); 4 background-color:#ddd; 5 background-image:none; 6 } 7 .simpleList .x-item-selected .x-list-disclosure { 8 background-color:#006bb6; 9 }
使用示例jsapp
1 Ext.define('app.view.new.List', { 2 alternateClassName: 'newList', 3 extend: 'ux.SimpleList', 4 requires: ['app.view.new.Info'], 5 xtype: 'newList', 6 config: { 7 store: 'newList', 8 cls: 'list', //自定義css 9 itemTpl: new Ext.XTemplate('<div class="left w20"><div class="img" style="background: url({litpic}) no-repeat center;background-size: 100%;"></div></div>', '<div class="right w80"><div class="row">{title}</div><div class="row grayF">{time}</div></div>') 10 } 11 });
控制器jside
1 /* 2 *新聞類 3 */ 4 Ext.define('app.controller.New', { 5 extend: 'Ext.app.Controller', 6 config: { 7 models: ['New'], 8 stores: ['NewList'], 9 views: ['new.List'], 10 refs: { 11 newList: 'newList' 12 }, 13 control: { 14 //新聞列表 15 newList: { 16 initialize: function (list) { 17 MyUtil.showListByParams('newList', MyUtil.newParams, MyUtil.isNewLoad); 18 }, 19 //itemtap事件被用來處理檢測是否在編輯狀態,因此這裏使用itemsingletap而不能使用itemtap 20 itemsingletap: function (list, index, target, record, e) { 21 this.redirectTo('newInfo'); 22 MyUtil.showInfo(record, 'newInfo', 'NewInfo.ashx', 'body', { 23 id: record.data.id 24 }); 25 }, 26 //結束多選事件觸發 27 simpleSuccess: function (list, items, ids, type) { 28 console.log(ids); 29 } 30 } 31 } 32 } 33 });
效果:ui
單擊 this
長按url
肯定後觸發simpleSuccess事件,輸出idsspa