插件代码

 /*
*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. js Jquery字符UrlEncode 编码 C#(asp.net)解码 Server HttpUtility 区别 cookies存中文

    一.Js asp.net 交互Url编码解码 C#(asp.net)编码:HttpUtility.UrlEncode(url) Jquery解码:decodeURIComponent(url); Jq ...

  2. php 字符串 以 开头 以结尾 startWith endWith

    From: http://www.shipingzhong.cn/node/1217 //第一个是原串,第二个是 部份串function startWith($str, $needle) { retu ...

  3. 《C程序猿从校园到职场》带领大家从校园走向职场

    七夕节刚过.就有好消息传来:本人新书<C程序猿从校园到职场>正式出版并在各大电商平台上发售了! 以下.让我们一起来赞赏一下纸质书的"风採"吧. 本书文件夹 第1章 概述 ...

  4. result源码

    CREATE TABLE `result` (`id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,`thetime` CHAR(100) , `category ...

  5. Node.js安装和入门 - 2行代码让你能够启动一个Server

    转自:http://josh-persistence.iteye.com/blog/1979552  备忘 Node.js是一个轻松构建快速,可扩展的网络应用平台建立在Chrome的JavaScrip ...

  6. windows mongodb最常用命令简单归纳

    在windows安装好了windows,首先记得要把mongodb bin目录路径放在 系统环境变量的path中,确定之后即配置好了mongo的环境变量,在dos命令框中输入mongo会出现如下 版本 ...

  7. FormData 对象的使用

    FormData 对象的使用 在本文章中 如何创建一个FormData对象 通过HTML表单创建FormData对象 使用FormData对象上传文件 通过AJAX提交表单和上传文件可以不使用Form ...

  8. ASP.NET MVC下Ajax.BeginForm方式无刷新提交表单

    有时候,不得不考虑到以下场景问题: 数据库表字段会频繁更改扩展,而流行的重业务的js框架过于依赖json数据接口,导致的问题是,数据库表更改 -> 数据接口更改 -> 前段框架逻辑更改.. ...

  9. 解决js中window.location.href不工作的问题

    E6中在html中<a>标识中通过JS添加click事件调用一个JS函数,例如: < script   type = "text/javascript" > ...

  10. [转]总结使用Unity 3D优化游戏运行性能的经验

    转载自:http://www.gameres.com/msg_221889.html 作者:Amir Fasshihi 流畅的游戏玩法来自流畅的帧率,而我们即将推出的动作平台游戏<Shadow ...