如何获取 YUI DataTable 中复选框的选中状态并由数据源中的数据设置?
我一整天都在谷歌上搜索这个问题,似乎找不到答案。当然也在这里搜索过,也没有找到,但是如果我在某个地方错过了答案,请原谅我。我确实尝试过!
我有一个包含 CheckBox 字段的 YUI DataTable。我希望根据我用作表的数据源的传入 JSON 数据来选中或取消选中此框。发生的情况是,所有行的复选框都被选中,并且我不知道该怎么做才能告诉它仅在字段值为“true”时才选中该框。这是我现在的代码:
createDataTable : function (data) {
var columnDefs = [
{ key: "Well", width : 30 },
{ key: "Value", field: "ReducedValue", width : 100 },
{ key: "Hit", width : 30, formatter:YAHOO.widget.DataTable.formatCheckbox},
{ key: "Reason", field: "reason", width : 200 }
];
var dataSource = new YAHOO.util.DataSource(data);
dataSource.responseType = YAHOO.util.DataSource.TYPE_JSARRAY;
dataSource.responseSchema = {
fields : [ "Well", "ReducedValue", "Hit", "reason" ]
};
var dataTable = new YAHOO.widget.ScrollingDataTable("data-table", columnDefs, dataSource, {height:"10em"});
$(".yui-dt table").css( { width : imageW } );
}
“Hit”字段是我在这里关心的字段。该字段值为“true”的传入数据应选中该复选框,否则应取消选中该复选框。
感谢您的帮助!
威廉
I've been googling this all day and can't seem to find an answer. Also searched here of course, and also didn't find it, but please forgive me if I've missed the answer somewhere. I did try!
I have a YUI DataTable that contains a CheckBox field. I would like to have this box checked or unchecked based in the incoming JSON data that I'm using as the DataSource for the table. What's happening is that the checkbox is checked for all rows, and I don't know what to do to tell it to only check the box if the field value is 'true'. Here's my code as of now:
createDataTable : function (data) {
var columnDefs = [
{ key: "Well", width : 30 },
{ key: "Value", field: "ReducedValue", width : 100 },
{ key: "Hit", width : 30, formatter:YAHOO.widget.DataTable.formatCheckbox},
{ key: "Reason", field: "reason", width : 200 }
];
var dataSource = new YAHOO.util.DataSource(data);
dataSource.responseType = YAHOO.util.DataSource.TYPE_JSARRAY;
dataSource.responseSchema = {
fields : [ "Well", "ReducedValue", "Hit", "reason" ]
};
var dataTable = new YAHOO.widget.ScrollingDataTable("data-table", columnDefs, dataSource, {height:"10em"});
$(".yui-dt table").css( { width : imageW } );
}
The 'Hit' field is the one I'm concerned with here. Incoming data with a value of 'true' for this field should have the checkbox checked, otherwise it should be unchecked.
Thanks for any help!
William
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
formatCheckbox 的实际代码如下。我只是猜测,但也许您传入的字符串“false”或字符串“0”实际上是 true 值。
The actual code for formatCheckbox is below. I'm just guessing, but maybe you're passing in the string 'false' or the string '0' which are actually true in value.