插件代码

 /*
*list tpl模版加入按钮监控
*<div class="x-button-normal x-button x-iconalign-center x-layout-box-item x-stretched btn"><span class="x-button-icon x-shown lower" fire="showWeibo"></span></div>
*fire="showWeibo" 作用是激活指定事件
*有两个参数cmp:视图本身以及doit
*只要是以上格式的模板都可以被监控到
*其中btn、lower为自定义样式,其他都是st自带样式
*/
Ext.define('ux.ListTpl', {
alias: 'plugin.ListTpl',
xtype: 'listTpl',
config: {
list: null,
//按下时添加css
pressedCls: 'pressing',
//监控对象选择器
delegate: 'div.x-button',
//是否监听input控件
isInput: false
},
constructor: function (config) {
this.initConfig(config);
this.callParent([config]);
},
//初始化
init: function (list) {
this.setList(list);
},
//更新配置
updateList: function (newList, oldList) {
if (newList) {
//为自定义按钮注册点击事件
newList.container.element.on({
tap: 'onTap',
touchstart: 'onPress',
touchend: 'onRelease',
delegate: this.getDelegate(),
scope: this
});
if (this.getIsInput()) {
//为自定义按钮注册点击事件
newList.container.element.on({
blur: 'onBlur',
delegate: 'input[type="text"]',
scope: this
});
} }
},
//执行动作
onTap: function (e) {
var me = this.getList(),
item = Ext.getCmp(Ext.get(e.getTarget()).up('.x-list-item').id),
index = item.$dataIndex,
record = me.getStore().getAt(index),
el = e.getTarget(this.getDelegate(), null, true),
fire = el.getAttribute('fire'),
action = 'do' + fire;
me.fireAction(fire, [me, record, item, index, el], action);
},
//按钮按下时,添加css
onPress: function (e, node) {
var el = e.getTarget(this.getDelegate(), null, true);
el.addCls(this.getPressedCls());
},
//按钮松开时,移除css
onRelease: function (e, node) {
var el = e.getTarget(this.getDelegate(), null, true);
el.removeCls(this.getPressedCls());
},
//焦点离开时,将值填充到store中
onBlur: function (e) {
var me = this.getList(),
item = Ext.getCmp(Ext.get(e.getTarget()).up('.x-list-item').id),
index = item.$dataIndex,
record = me.getStore().getAt(index),
el = e.getTarget('input', null, true),
value = el.getValue(),
name = el.getAttribute('name');
record.data[name] = value;
}
});

使用代码:

 Ext.define('app.view.eatery.Shop', {
alternateClassName: 'eateryShop',
extend: 'Ext.List',
xtype: 'eateryShop',
requires: ['ux.ListTpl'],
config: {
cls: 'list',
plugins: [{
xtype: 'listTpl',
isInput: true
}],
title: '购物车',
btmBar: 'eateryBar',
isNoHide: true,
scrollToTopOnRefresh: false,
itemTpl: new Ext.XTemplate(
'<div class="bh">',
'<div class="bone">{name}</div>',
'<div class="bh">',
'<div class="x-button-normal x-button x-iconalign-center x-layout-box-item x-stretched btn" style="visibility:{visibility}" fire="onTasteUp" value="-1"><span class="x-button-icon x-shown lower"></span></div>',
'{taste}',
'<div class="x-button-normal x-button x-iconalign-center x-layout-box-item x-stretched btn" fire="onTasteUp" value="1"><span class="x-button-icon x-shown add"></span></div>',
'</div>',
'</div>',
'<div>{price}</div>',
'<div>备注:<input type="text" name="description" value="{description}"/></div>'),
store: 'shopList',
selectedCls: '',
pressedCls: ''
}
});

监听代码:

  eateryList: {
onTasteUp: function (list, index, record, btn) {
var visibility = 'visible',
value = +btn.getAttribute("value"),
taste = record.data.taste + value;
if (taste == 0) {
visibility = 'hidden';
}
record.set({ taste: taste, visibility: visibility });
}
}

效果图:

2013.9.15

优化代码,参考list源码书写。为控件添加点击事件和点击方法,不再触发list默认单击事件

添加了对输入框的支持,可自动将输入框中的值填充到数据源中

sencha touch list tpl 监听组件插件(2013-9-15)的更多相关文章

  1. sencha touch Container tpl 监听组件插件(2013-9-14)

    将http://www.cnblogs.com/mlzs/p/3279162.html中的功能插件化 插件代码: /* *tpl模版加入按钮 *<div class="x-button ...

  2. Bootstrap滚动监听(Scrollspy)插件

    Bootstrap滚动监听(Scrollspy)插件,即自动更新导航插件,会根据滚动条的位置自动更新对应的导航目标

  3. waypoint+animate元素滚动监听触发插件实现页面动画效果

    最近在做一个官网类型滚动加载动画,使用到waypoint监听事件插件和animate动画样式,两者结合完美实现向下滚动加载动画,但是没有做向上滚动撤消动画,留待以后有空研究 首先来介绍下jquery. ...

  4. Vue中如何监听组件的原生事件

    在首页开发中,右下角有一个返回顶部的小箭头,将它单独封装成一个BackTop组件,但是它何时出现需要依赖于首页的滑动,即另外一个Scroll组件.如果直接在BackTop组件里面监听,则需要通过thi ...

  5. sencha touch Container 监听超链接插件

    有时候内容直接从后台获取,有可能包含超链接,打包成应用之后,点击会造成不好的后果,这样做能够用外部浏览器打开.需要Cordova支持 监听插件代码: /* *监听a标签,用外部浏览器打开链接 */ E ...

  6. 12.vue属性.监听.组件

    1.计算属性 https://cn.vuejs.org/v2/guide/computed.html new Vue({ computed:{//定义 show(){ } } }) ++计算属性1.h ...

  7. sencha touch 2.2 为list PullRefresh插件添加refreshFn方法

    sencha touch 2.2 list PullRefresh插件没有refreshFn方法 但是我们又需要他,所以需要自行扩展 代码如下 /** * 重写下拉刷新插件,以支持refreshFn事 ...

  8. bootstrap源码之滚动监听组件scrollspy.js详解

    其实滚动监听使用的情况还是很多的,比如导航居于右侧,当主题内容滚动某一块的时候,右侧导航对应的要高亮. 实现功能 1.当滚动区域内设置的hashkey距离顶点到有效位置时,就关联设置其导航上的指定项 ...

  9. listview监听组件内容变化

    package com.meizu.ui.gifts; import android.app.Activity; import android.content.Context; import andr ...

随机推荐

  1. C# 文件过滤器filter

    OpenFileDialog对话框的Filter属性说明: 首先说明一个示例,分析一下Filter属性的构成:“ Excel文件|*.xls ”,前面的“Excel文件”成为标签,是一个可读的字符串, ...

  2. php + ajax 避免重复提交

  3. linux和windows互传文件/用户配置文件和密码配置文件/用户组管理/用户管理

    2.27linux和windows互传文件 3.1 用户配置文件和密码配置文件 3.2 用户组管理 3.3 用户管理 linux和windows互传文件 显示日期date [root@centos_1 ...

  4. 【伪装位置神器】神行者AnyLocation 1.3.0001可用于微信,陌陌

    <ignore_js_op> 软件名称:神行者(破解)软件版本:v1.3.0001授权类别:免费测试机型:大可乐手机 下载链接: http://pan.baidu.com/s/1qWwSM ...

  5. GridView如何将分页数据全部导出为EXCEL?

    GRIDVIEW分页状态下将全部数据导出 protected void Button2_Click(object sender, EventArgs e)//按button2将gridview将数据导 ...

  6. 微信小程序使用阿里图标

    微信小程序不支持外联阿里图标,必须下载放入小程序的本地文件中. 步骤一:下载项目图标 步骤二:转换iconfont.ttf文件(小程序的wxss文件的font-face的url不接受http地址作为参 ...

  7. debian、ubuntu:使用apt包管理器可能存在的问题! 让新手望而却步!

    apt包管理器说好真好,说不好真不好. 最近在debian9.ubuntu18.04上安装oracle 10g 玩. 怎么都准备不好安装环境.原因就是i386构架体系的deb包总安装不正确! baid ...

  8. Python 多线程相关知识学习

    多线程类似于同时执行多个不同程序,多线程运行有如下优点: 使用线程可以把占据长时间的程序中的任务放到后台去处理. 用户界面可以更加吸引人,这样比如用户点击了一个按钮去触发某些事件的处理,可以弹出一个进 ...

  9. Python之XML解析详解

    什么是XML? XML 指可扩展标记语言(eXtensible Markup Language). XML 被设计用来传输和存储数据. XML是一套定义语义标记的规则,这些标记将文档分成许多部件并对这 ...

  10. golang-defer坑的本质

    https://blog.csdn.net/hittata/article/details/77836435