有人可以向我解释此代码的作用吗?

dojo[(show ? "remove" : "add") + "Class"](this.listNode, "tweetviewHidden");


这是此函数值所属的函数:

// Provide the class
dojo.provide("tweetview._ViewMixin");
 
// Declare the class
dojo.declare("tweetview._ViewMixin", null, {
    // Returns this pane's list
    getListNode: function() {
        return this.getElements("tweetviewList",this.domNode)[0];
    },
    // Updates the list widget's state
    showListNode: function(show) {
        dojo[(show ? "remove" : "add") + "Class"](this.listNode, "tweetviewHidden");
    },
    // Pushes data into a template - primitive
    substitute: function(template,obj) {
        return template.replace(/\$\{([^\s\:\}]+)(?:\:([^\s\:\}]+))?\}/g, function(match,key){
            return obj[key];
        });
    },
    // Get elements by CSS class name
    getElements: function(cssClass,rootNode) {
        return (rootNode || dojo.body()).getElementsByClassName(cssClass);
    }
});


资料来源:http://dojotoolkit.org/documentation/tutorials/1.6/mobile/tweetview/starting_tweetview

最佳答案

非常简单,如果show为true,则将调用dojo.removeClass(this.listNode, "tweetviewHidden");;如果为false,则将调用dojo.addClass(this.listNode, "tweetviewHidden");
本质上是其切换功能。

[]括号打开一个对象,可通过键访问该值。就像var bla={"foo":"bar"}; bla["foo"];。现在,由于其道场,该值是一个函数,将被执行

07-24 17:31
查看更多