插件代码

 /*
*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. Web APi之HttpClient注意事项以及建议

    Web APi之HttpClient注意事项以及建议 前言 之前对于用SelfHost来手动实现Web API的宿主模式,似乎不是太深入,所以本篇文章我们一起来讨论关于利用HttpClient来访问W ...

  2. Mybatis中#和$区别(带脑图)

    零.引言 使用 #{name} 的时候,MyBatis会进行预编译,防止SQL注入的问题(官方话) 用一个通俗一点的例子来解释,比如有如下MyBatis的SQL语句 21.#{}和${}的区别.png ...

  3. spring 配置 Java配置类装配bean

    https://www.cnblogs.com/chenbenbuyi/p/8457700.html 自动化装配的确有很大的便利性,但是却并不能适用在所有的应用场景,比如需要装配的组件类不是由自己的应 ...

  4. js如何获取asp.net服务器端控件的值(label,textbox,dropdownlist,radiobuttonlist等)

    js如何获取asp.net服务器端控件的值(label,textbox,dropdownlist,radiobuttonlist等) 欢迎访问原稿:http://hi.baidu.com/2wixia ...

  5. 安卓开发笔记——GridView组件

    1.什么是GridView? GridView(网格视图)是按照行列的方式来显示内容的,一般用于显示图片,图片等内容,比如实现九宫格图,用GridView是首选,也是最简单的. 2.正文 GridVi ...

  6. daterangepicker日历插件使用参数注意问题

    显示具体时间时分秒: timePicker设置为true,//有些资料写的pickerTime不太对 重点大坑:修改时间默认展示格式,把fomat写在locale中,网上很多资料说直接写在datera ...

  7. es 5 数组reduce方法记忆

    reduce() 方法接收一个函数作为累加器(accumulator),数组中的每个值(从左到右)开始合并,最终为一个值. 概念:对数组中的所有元素调用指定的回调函数.该回调函数的返回值为累积结果,并 ...

  8. 5 云计算系列之glance镜像服务安装

    preface 在上节中我们了解了keystone服务,下面就看看glance管理镜像的服务吧. glance组成 glance有两部分组成: glance-api 接受云系统镜像的创建,删除,读取请 ...

  9. Oracle:oracle 12.1.0.2 升级到12.2.0.1 后,自动任务报错:ORA-20001: Statistics Advisor: Invalid task name for the current user

    具体错误如下:关键字:ORA-12012.ORA-20001 ORA-12012: error on auto execute of job "SYS"."ORA$AT_ ...

  10. redhat enterprise edition 6.8:禁止ipv6后,nfs文件系统无法挂载:no such device

    如题:谨记. 附注:如何禁止ipv6? 方法一 第一种方法是通过 /etc/sysctl.conf 文件对 /proc 进行永久修改. 换句话说,就是用文本编辑器打开 /etc/sysctl.conf ...