开发者

Passing parameter in javascript function is giving error

开发者 https://www.devze.com 2023-02-17 04:43 出处:网络
I am using extjs grid , and i put a render function on a coloumn of a grid /** * function for rendering the link

I am using extjs grid , and i put a render function on a coloumn of a grid

/** 
    * function for rendering the link
    **/
    function linkRenderer(data, cell, record, rowIndex, columnIndex, store) {
        console.log(record.id);
        if  (data != null)  {
            return开发者_运维知识库 '<a href="javascript:void(0)" onclick="resellerwindow('+record.id+')">' + data + '</a>';
        }
        return data;
    }

while on clicking the link i got an error that whatever the value of record.id is not not defined

Please suggest what solution i can do .


Do you have a idProperty set for your store? set the idProperty to one of the values used to identify unique records. This will ensure that record.id is set to a value. For accessing all other values of the record, you will have to access them through record.data.proerty

Update: You need to use escape characters so that the string values are properly passed to the resellerwindow method:

<a href="javascript:void(0)" onclick="resellerwindow(\''+record.id+'\')"> + data + '</a>'


But that's pretty clear the value of record.id is not define. Dah!


If the output of your console log is a string you are calling your function wrong, you are missing some quotes if record.id is a string.

function linkRenderer(data, cell, record, rowIndex, columnIndex, store) {
    if  (data != null)  {
        return String.format('<a href="javascript:void(0)" onclick="resellerwindow(\'{0}\')">{1}</a>', record.id, data);
    }
    return data;
}
0

精彩评论

暂无评论...
验证码 换一张
取 消