簡體   English   中英

從您單擊的行上的列中獲取數據

[英]Get the data from a column on the row that you click

我有一個YUI數據表如下

YAHOO.example.Data = {
        bookorders: [
            {id:"po-0167", date:new Date(1980, 2, 24), quantity:1, amount:4, title:"A Book About Nothing"},
            {id:"po-0783", date:new Date("January 3, 1983"), quantity:null, amount:12.12345, title:"The Meaning of Life"},
            {id:"po-0297", date:new Date(1978, 11, 12), quantity:12, amount:1.25, title:"This Book Was Meant to Be Read Aloud"},
            {id:"po-1482", date:new Date("March 11, 1985"), quantity:6, amount:3.5, title:"Read Me Twice"}
        ]
    }

我添加了一個訂閱事件

myDataTable.subscribe("rowClickEvent", function(args){   
            alert("inside click1");

            var rec = myDataTable.getSelectedRows()[0];
            .
            .
            .
            printTitle(record.title);
        });

問題是我無法設法獲得所選行。 我有另一個函數printTitle來提醒單擊該行的書的標題。

我設法使用myDataTable.getSelectedRows()[0]獲取selectedRow。 我更新了我的代碼,但現在我似乎無法獲得標題。

正在通過論壇尋找更多的靈感我偶然發現了這一點

關於yui行點擊事件的另一個問題

最后我替換了getselectedrows

myDataTable.subscribe("rowClickEvent", function(args){   

            var record = this.getRecord(args.target);
            var title = record.getData("title");

            alert("inside click2 : " + title);

        });

它就像一個魅力

我覺得你很親密。

請嘗試以下方法:

請注意“var selectedRecordId = myDatatable.getSelectedRows()[0];” 給你記錄的id。 您可能需要執行“var selectedRecord = myDatatable.getRecord(id);” 得到你的記錄。 當你有記錄時,你需要使用“var title = selectedRecord.getData('title');” 得到標題。

檢查那些文檔(幫助我回答): http//developer.yahoo.com/yui/docs/YAHOO.widget.Record.html http://developer.yahoo.com/yui/docs/YAHOO.widget.DataTable html的

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM