插件代码

 /*
*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. Redis Crackit漏洞利用和防护

    注意:本文只是阐述该漏洞的利用方式和如何预防.根据职业道德和<中华人民共和国计算机信息系统安全保护条例>,如果发现的别人的漏洞,千万不要轻易入侵,这个是明确的违法的哦!!! 目前Redis ...

  2. BarTender出现3702错误怎么办

    很多时候,在我们不经意间,BarTender条码打印软件就会弹出各种错误消息,其实都是一些常见的小问题,是我们操作不当引起的,本文,小编就给大家来讲解BarTender错误消息3702的解决办法. 错 ...

  3. Synycovery 7.18f 一个优秀的同步软件

    Serial Key Name: Vdown RG Code: MCKOFA7MNGUQY7954

  4. Apache+php5

    .下载回来的是解压文件,解压好放到要安装的位置.(我这里以D:\Acpache24为例) .打开Apache24\conf下httpd.conf 文件,用记事本打开即可. ()第37行ServerRo ...

  5. mysql中floor函数的作用是什么?

    需求描述: 最近写mysql程序的时候,使用了floor函数,在此记录下该函数的作用 操作过程: 1.使用floor函数的测试 mysql> select floor(1.23),floor(- ...

  6. A股最新的自由现金流和折现估值查询

    A股最新的自由现金流折现估值,利用自由现金流折现的经典公式,采用 8%.9%.10%.11%.12%.15% 等贴现率来进行估值. SH600000:浦发银行的最新自由现金流和折现估值模型: 浦发银行 ...

  7. python使用tkinter写带界面的工具

    python一般用来写纯脚本的居多,但也可以做有视图的产品出来,例如做网页和客户端工具.做成工具的好处是,让不懂代码的人也能使用,不需要去修改代码里面的参数,如果使用次数频繁,甚至比纯脚本跟节约时间: ...

  8. 条件独立(conditional independence) 结合贝叶斯网络(Bayesian network) 概率有向图 (PRML8.2总结)

    本文会利用到上篇,博客的分解定理,需要的可以查找上篇博客 D-separation对任何用有向图表示的概率模型都成立,无论随机变量是离散还是连续,还是两者的结合. 部分图为手写,由于本人字很丑,望见谅 ...

  9. XMPP协议实现即时通讯底层书写 (一)--从RFC6121阅读開始

    Extensible Messaging and Presence Protocol (XMPP): Instant Messaging and Presence ok,额瑞巴蒂,说好的阅读RFC61 ...

  10. ios开发之--编码及命名规范

    做了几年的开发工作,因为是半路出的家,所以对这块一直都没怎么重视,所以在工作中,出现了很多的尴尬场景,编码和命名的规范是一定得有的,最起码一个团队之间的规范也是很有必要的.面向对象的编程,其实很好理解 ...