我正在使用YUI(YAHOO用户界面库)和Velocity开发一个网页,我在其中一个列中设置了一些带有一些按钮的数据表。我的问题是,当我对任何列进行排序时,按钮不再呈现,即显示为简单的输入字段。这是(简化)代码的一部分:
#set($states=['valid','invalid','empty'])
var buttonsFormatter = function(elLiner, oRecord, oColumn, oData) {
elLiner.innerHTML = '';
#foreach($state in $states)
elLiner.innerHTML = elLiner.innerHTML+'<input id="${state}Button-'+oRecord.getData("id")+'"/>';
#end
};
var myColumnDefs = [
{key:"change",
label: "Actions",
formatter: buttonsFormatter,
sortable: true,
resizeable: true},
];
// Then create datasource, datatable, etc...
// $comment is the object I use to build the datasource
// So here I loop over records to instantiate the buttons
#foreach($comment in $comments_arraylist)
new YAHOO.widget.Button("validButton-"+$comment.getId(),
{label:'<img src="$content.getURI("images/gc.gif")"/>',
title:'Valid',
onclick:{ fn:makeRequest,obj:[$comment.getId(),"Valid"]}
}
);
new YAHOO.widget.Button("invalidButton-"+$comment.getId(),
{label:'<img src="$content.getURI("images/rc.gif")"/>',
title:'Invalid',
onclick:{ fn:makeRequest,obj:[$comment.getId(),"Invalid"]}
}
);
new YAHOO.widget.Button("emptyButton-"+$comment.getId(),
{label:'<img src="$content.getURI("images/close.jpg")"/>',
title:'Reset',
onclick:{ fn:makeRequest,obj:[$comment.getId(),"null"]}
}
);
#end
我还尝试在formatter函数中添加 new YAHOO.widget.Button ... 声明,但没有更多成功。有人对我有想法吗?我必须提到除了这个关于排序的问题,一切正常。
由于
亚历
编辑:通过这种方式修改按钮格式化程序功能无效:
var buttonsFormatter = function(elLiner, oRecord, oColumn, oData) {
elLiner.innerHTML = '';
#foreach($state in $states)
elLiner.innerHTML = elLiner.innerHTML+'<input type="button" id="${state}Button-'+oRecord.getData("id")+'"/>';
#end
elLiner.innerHTML = elLiner.innerHTML+'<input type="button" id="testButton-'+oRecord.getData("id")+'"/>';
new YAHOO.widget.Button("testButton-"+oRecord.getData("id"),
{label:'<img src="$content.getURI("images/gc.gif")"/>',
title:'test',
onclick:{ fn:makeRequest,obj:[oRecord.getData("id"),"test"]}
}
);
};
这样创建的“测试”按钮永远不会呈现,只显示为基本的空按钮输入。
答案 0 :(得分:0)
您的“buttonsFormatter”函数正在创建文本输入元素。我认为你需要在你创建的元素上有一个'type =“button”'属性。
我想我理解你为什么要调用新的YAHOO.widget.Button,但是你应该在formatter函数中这样做。