如何在字符串中加对象

使用easyUI 的表格 其中的返回的 a中onclick事件传的参数要五个,感觉好麻烦 记的以前用bootstrap传过对象回去 这回传rowData的话 alert rowData会出现undefined 在页面调试中也没办法看到值只看到一个object Object

 {
                                    field : 'action',
                                    title : '操作',
                                    width : 100,
                                    align : 'center',
                                    rowspan : 2,
                                    formatter : function(value, rowData,
                                            rowIndex) {
                                        var a = '<a href="javascript:void(0);" id="edit'+rowIndex+'" class="easyui-linkbutton" iconCls="icon-mini-edit" plain="true" onclick="bfupdate('+ rowData.ID+','+rowData.BTS_CHECKSTATUS+')">编辑</a> ';

                                        return a;


                                    }
                                }

要想在字符串中加对象,你需要看看json

将rowData用JSON.stringify转为json字符赋值给a的一个自定义属性(注意字符串"的转义替换,防止字符串不闭合),方法通过自定属性得到json字符串后eval后JSON.parse转为json对象,IE8-要导入json2.js,要不不支持JSON对象

         formatter: function (value, rowData, rowIndex) {
            var a = '<a href="javascript:void(0);" data="'+JSON.stringify(rowData).replace(/"/g,'&quot;')+'" id="edit' + rowIndex + '" class="easyui-linkbutton" iconCls="icon-mini-edit" plain="true" onclick="bfupdate(this)">编辑</a> ';

            return a;


        }

    function bfupdate(a) {
        var d = a.getAttribute('data').replace(/&quot;/g, '"');
        d = JSON.parse(d)
        alert(d.ID)
        alert(d.BTS_CHECKSTATUS)
        //...more property
    }