2013-05-30 47 views
0

我已经添加了一些新的过滤器给Alfresco Share中的数据列表。现在,我想在默认情况下选择我的新过滤器中的一个(而不是“All”默认过滤器),以便输入我的数据列表。扩展yui2 - 如何以正确的方式覆盖类属性

我发现默认过滤器在YUI2组分负责的构造函数中设置渲染数据一览:

/** 
* DataGrid constructor. 
* 
* @param htmlId {String} The HTML id of the parent element 
* @return {Alfresco.component.DataGrid} The new DataGrid instance 
* @constructor 
*/ 


Alfresco.component.DataGrid = function(htmlId) 
    { 
     Alfresco.component.DataGrid.superclass.constructor.call(this, "Alfresco.component.DataGrid", htmlId, ["button", "container", "datasource", "datatable", "paginator", "animation", "history"]); 
    // Initialise prototype properties 
    this.datalistMeta = {}; 
    this.datalistColumns = {}; 
    this.dataRequestFields = []; 
    this.dataResponseFields = []; 
    this.currentPage = 1; 
    this.totalRecords = 0; 
    this.showingMoreActions = false; 
    this.hideMoreActionsFn = null; 
    this.currentFilter = 
    { 
    filterId: "all", 
    filterData: "" 
    }; 
    this.selectedItems = {}; 
    this.afterDataGridUpdate = []; 

我已经扩展此组件用于其他目的(渲染列一个特殊的方式等),现在我想改变this.currentFilter.filterId为“活跃”(这是我的新过滤器)。

这是你如何扩展类和覆盖了一个方法:

// Extend default DataList... 
    YAHOO.extend(Datalist.custom.DataGrid, Alfresco.component.DataGrid, 
    { 
    onFilterChanged: function CustomDL_onFilterChanged(layer, args) 
    { 
     // Call super class method... 
     Datalist.custom.DataGrid.superclass.onFilterChanged.call(this, layer,args); 
    // Pop-up a message... 
    Alfresco.util.PopupManager.displayMessage({ 
    text: "Filter Changed!" 
    }); 
} 

}); })();

但是,我还没有找到重写类属性的方法,例如“this.currentFilter”,我只能成功重写方法。

我查看了YUI.lang.augmentProto和YUI.lang.augmentObject,却没有真正理解如何去做。

回答

1

你可以重写属性的初始值,但它不会有太大的区别,因为它在构造函数中被初始化,所以无论初始值是什么,它都会丢失。

您应该重写构造函数,方法与DataGrid重写其基类的构造函数的方式相同。调用原始构造函数,然后为该属性设置一个新值。