0

我有以下代码(见下文)。问题是当列 condition1 的值为 0 时,如何隐藏列 quantity_value1 的格式化程序文本框。

var response = {
    "id": 1,
    "items": [
        {"condition1": 1, "quantity_value1":"value1"},
        {"condition1": 1, "quantity_value1":"value2"},
        {"condition1": 0, "quantity_value1":"value3"},
        {"condition1": 1, "quantity_value1":"value4"},
        {"condition1": 0, "quantity_value1":"value5"}            
    ]
};

var bpColumns = [
    {label:'header1', children:[
    {
        key:"condition1"
    },
    {
        key:"quantity_value1",
        formatter:YAHOO.widget.DataTable.formatTextbox
    }]}
];
YAHOO.example.Data = response;
this.bpDataSource = new YAHOO.util.DataSource(YAHOO.example.Data);
this.bpDataSource.responseType = YAHOO.util.DataSource.TYPE_JSON;
this.bpDataSource.responseSchema = {
    resultsList: "items",
    fields: ["condition1","quantity_value1"]
};
this.standardSelectDataTable = new YAHOO.widget.ScrollingDataTable("mydiv",
    bpColumns, this.bpDataSource, {height:"15em"});
4

2 回答 2

1

您必须编写自己的格式化程序,如用户指南中所示这里有一个例子。没有办法配置内置的,但您可以将其用作您的版本的基础,在中搜索 formatTextbox 。

于 2013-10-22T07:18:29.930 回答
0

这有效:

            var response = {
                "id": 1,
                "items": [
                    {"condition1": 1, "quantity_value1":"value1"},
                    {"condition1": 1, "quantity_value1":"value2"},
                    {"condition1": 0, "quantity_value1":"value3"},
                    {"condition1": 1, "quantity_value1":"value4"},
                    {"condition1": 0, "quantity_value1":"value5"}            
                ]
            };
            var bpColumns = [
                {label:'header1', children:[
                        {
                            key:"condition1"
                        },
                        {
                            key:"quantity_value1",
                            formatter:"formatTextbox"
                        }]}
            ];
            var vrecord = null;
            YAHOO.example.Data = response;
            this.formatTextbox = function(el, oRecord, oColumn, oData, oDataTable) {
                if (oRecord.getData("condition1") === 1){
                    var value = (YAHOO.lang.isValue(oData)) ? YAHOO.lang.escapeHTML(oData.toString()) : "";
                    var input = document.createElement("input");
                    input.type = "text";
                    input.value = value;
                    input.onchange = function()
                    {
                        vrecord.setData("quantity_value1",this.value);
                        console.log(vrecord);
                    };
                    el.appendChild(input);
                }
            };
            // Add the custom formatter to the shortcuts
            YAHOO.widget.DataTable.Formatter.formatTextbox = this.formatTextbox;
            this.bpDataSource = new YAHOO.util.DataSource(YAHOO.example.Data);
            this.bpDataSource.responseType = YAHOO.util.DataSource.TYPE_JSON;
            this.bpDataSource.responseSchema = {
                resultsList: "items",
                fields: ["condition1","quantity_value1"]
            };
            this.standardSelectDataTable = new YAHOO.widget.ScrollingDataTable("mydiv",
            bpColumns, this.bpDataSource, {height:"15em"});
            this.standardSelectDataTable.subscribe("rowClickEvent", this.standardSelectDataTable.onEventSelectRow);
            this.standardSelectDataTable.subscribe("rowClickEvent", function(event, target) {
                var selectedRows = this.getSelectedRows();
                vrecord = this.getRecord(selectedRows[0]);
            });
于 2013-10-24T20:01:01.700 回答