`

YUI3 Infrastructure下的 Attribute

yui 
阅读更多


此图转载于:http://houfeng0923.iteye.com/blog/1113593

提供扩展属性管理系统,它可以扩展任何类,包括get/set和内部的change事件,

增加类的属性:

 

YUI().use("attribute", function(Y) {

    function MyClass() {
        ...
    }

    Y.augment(MyClass, Y.Attribute);
});

 

 

设置类的属性:

 

var o = new MyClass({
    attrA:5
});

// Set attrB later on
o.set("attrB", "Hello World!");

 

 

配置类的属性:

 

 

 

function MyClass(userValues) {var attributeConfig = {
    attrA : {
        // Configuration for attribute "attrA"

        value: 5,

        setter: function(val) {
            return Math.min(val, 10); 
        },

        validator: function(val) {
            return Y.Lang.isNumber(val);
        }
    },

    attrB : {
        // Configuration for attribute "attrB"
    }
};

this.addAttrs(attributeConfig, userValues);

或者使用addAttr

 

this.addAttr("attrA", {
    // Configuration for attribute "attrA"

    value: 5,

    setter: function(val) {
        return Math.min(val, 10); 
    },

    validator: function(val) {
        return Y.Lang.isNumber(val);
    }
});

 

change事件:

 

o.on("enabledChange", function(event) {

    // event.prevVal will contain the current attribute value
    var val = event.prevVal;

    if (val !== someCondition) {
        // Prevent "enabled" from being changed
        event.preventDefault();
    }

});

 

 

Getting/Setting Sub Attribute Values

 

o.set("strings", {
    ui : {
        accept_label : "OK",
        decline_label : "Cancel",
    },
    errors : {
        e1000 : "Not Supported",
        e1001 : "Network Error"
    }
});

o.set("strings.ui.accept_label", "Yes");
o.set("strings.ui.decline_label", "No");

// Add a new property
o.set("strings.errors.e2000", "New Error");

// Cannot set new intermediate properties:
// "strings.messages" does not exist so can't set
// "strings.messages.intro"
o.set("strings.messages.intro", "Welcome");
var lbl = o.get("strings.ui.accept_label");

 

  • 大小: 198.7 KB
分享到:
评论

相关推荐

    yui3-master.zip

    yui3-master.zip

    YUI3 dialog组件

    基于YUI3的dialog组件该组件是基于YUI3开发的,功能强大,详细见http://www.qiqicartoon.com

    YUI 入门教程YUI 入门教程YUI 入门教程

    YUI教程YUI 入门教程YUI 入门教程YUI 入门教程

    从YUI2到YUI3看前端的演变 pdf

    YUI3 引入了粒度更细的模块管理方式,通过异步 HTTP 请求加载模块、然后执行回调来加载和使用模块。现场有很多人提出疑问,大家无非关心的是“效率”二字。个人以为在现阶段,这种方式有一点激进,否能为广大用户所...

    从YUI2到YUI3看前端的演变

    从YUI2到YUI3看前端的演变

    YUI3 完整包

    Yahoo! UI Library (YUI) 是一个开放源代码的 JavaScript 函数库,为了能建立一个高互动的网页,它采用了AJAX, DHTML 和 DOM 等程式码技术。它也包含了许多 CSS 资源。

    yuicompressor-yui compressor

    将yuicompressor-2.4.2.jar 放在c:下,将editor.js放在c:盘下。 将editor.js进行压缩 命令为: C:\java -jar yuicompressor-2.4.2.jar editor.js -o editor2.js 参数说明: yuicompressor-2.4.2.jar 为工具包...

    yui3-3.17.2最新版

    yui对于开发者来说是绝对的好用,开发者福利,特献上最新版

    yui_2.9.0前端UI

    YUI 库,全称Yahoo! UI Library。是一组工具和控件,用JavaScript写成, 为的是用DOM 脚本,DHTML和AJAX等技术创建丰富的网页交互式应用程序。 YUI 基于BSD协议,对所有的使用方式都是免费的。YUI 项目包括YUI 库和两...

    yui 3.1.2 源码 6MB大小 0资源分

    YUI3 源码 非compress版 YUI3 源码 非compress版 YUI3 源码 非compress版

    高效WEB前端开发之路:YUI3.15

     本书作者便是在此背景下,以国外最优秀的JavaScript框架之一——Yahoo User Interface Library(简称YUI)的最新版本YUI 3.15为基础编写而成。本书通过通俗易懂的语言和大量丰富的实例,帮助读者解决实际生产环境...

    YUI3 中tree的两种实现

    NULL 博文链接:https://ttwang.iteye.com/blog/1741631

    YUI3.6文档及示例

    yui官网下载的。内容很全,示例+doc说明

    yuitest YUI测试工具

    YUI Test is a complete testing framework for JavaScript and Web applications. You can use the simple JavaScript syntax to write unit tests that can be run in web browsers or on the command line, as ...

    yui_2.6.0r2

    yui_2.6.0r2 yui_2.6.0r2 yui_2.6.0r2 yui_2.6.0r2 yui_2.6.0r2

    js 压缩YUI

    雅虎的东西,简单的操作很好用 使用例子:java -jar D:\yuicompressor\yuicompressor\yuicompressor.jar E:\js\all.js -o E:\wap\wap2\js\all-min.js --charset utf-8 当然要装jdk了 不然就玩完了

    yui 资源包

    yui 源码下载,3.9.0 r2 包,最新版本

    yuicompressor,给YUI Compressor添加右键命令

    YUI Compressor非常好用,特别是JS的混淆是众多JS Coding的最爱。可惜官网提供的版本都不具备右键功能,每次压缩都要cmd输入一些命令实在是繁琐,本文就介绍如何给YUI Compressor添加右键命令,方便使用。 网上已有...

    YUI3 Cookbook

    YUI3 Cookbook for Yahoo User Interface 3

Global site tag (gtag.js) - Google Analytics