zoukankan      html  css  js  c++  java
  • Jquery Mobile开发以及Js对象动态绑定

    动态创建对象并绑定属性:

                var instantiate = function (Type, args) {
                    var Constructor = function () { };
                    Constructor.prototype = Type.prototype;
    
                    var obj = new Constructor();
    
                    Type.apply(obj, args);
    
                    return obj;
                };
    
                var AssetObj = function () {
    
                };
    
    
    
                AssetObj.prototype.getAssetName = function (AssetName) {
                    return "AssetName:" + this[AssetName] + ",data:" + this[AssetName + "DataObjs"] + "Length:" + this[AssetName + "DataObjs"].length;
                };
    
    
    
    
                AssetObj.prototype.set = function (Asset, data) {
                    this[Asset] = Asset;
                    if (this[Asset + "DataObjs"] == null || this[Asset + "DataObjs"] == undefined) {
                        this[Asset + "DataObjs"] = new Array();
                        this[Asset + "DataObjs"].push(data);
                    } else {
                        this[Asset + "DataObjs"].push(data);
                    }
                }
    
    
                //
                var assetObjs = instantiate(AssetObj);
                var regionObjs = instantiate(AssetObj);
    
                //assetObjs.set("ISCS", "ISCS_DATA1");
                //assetObjs.set("ISCS", "ISCS_DATA2");
                //assetObjs.set("HHO", "HHO_DATA");
                //alert("person2:" + assetObjs.getAssetName('ISCS'));
                //alert("person3:" + assetObjs.getAssetName('HHO'));
    
                $.each(items, function (k, v) {
                    assetObjs.set(v.Asset, v);
                    regionObjs.set(v.Region, v);
                });

    Jquery属性选择器:

    源码示例:

    //获取页面data-role="page"和data-role="dialog"的数目
    //#7470
    var $pages = $(":jqmData(role='page'),:jqmData(role='dialog')")
    

    那我来大家来看一下到底是咋样实现的呢?

    源码展示:

    var oldFind = $.find,
    	jqmDataRE = /:jqmData(([^)]*))/g;
    	
    $.find = function(selector,context,ret,extra){
    	//注意这边会按照jquery mobile的特性写法,进行一层过滤
    	selector = selector.replace(jqmDataRE,"[data-" + ($.mobile.ns || "") + "$1]");
    	//比如selector为":jqmData(role='page')",替换后的"[data-role='page']"
    	return oldFind.call(this,selector,context,ret,extra);
    };	
    

    说明;
    1、其实在jquery mobile体系中,内部处理了一下$.find,对:jqmData这种选择器进行处理

  • 相关阅读:
    MySQL行级锁、表级锁、页级锁详细介绍
    Spring REST是什么?(转)
    Spring REST(转)
    联系人项目
    三级联动(有刷新)
    Java中点击按钮返回上一页
    Java中隐藏显示效果
    理解RESTful架构(转)
    什么是REST?以及RESTful的实现(转)
    JSTL 核心标签库 使用(转)
  • 原文地址:https://www.cnblogs.com/skybreak/p/3360787.html
Copyright © 2011-2022 走看看