使用 GWT 显示不确定的复选框 Bootstrap
Displaying an indeterminate checkbox with GWT Bootstrap
我希望能够在 GWT 中将 Bootstrap 复选框设置为 "indeterminate" 状态。我写了下面的代码:
/**
* JavaScript to give an ID'd element in a form the focus
*
* @param checkbox Element to manipulate
* @param indeterminate True if indeterminate, false if not
*/
public static native void setIndeterminate (Element checkbox, boolean indeterminate) /*-{
checkbox.indeterminate = indeterminate;
}-*/;
运行 this in Chrome 调试器告诉我复选框设置为 indeterminate = true,但它仍然显示为未选中。当我显示 this page 时,我正确地看到了不确定的复选框,所以这不是浏览器问题。
关于如何解决这个问题有什么建议吗?
为什么需要 JSNI 代码?
您可以使用以下
Checkbox checkbox = new Checkbox("Some-Label");
checkbox.getElement().setAttribute("indeterminate", true /*Or false*/);
编辑
刚刚查看了一些文档和博客文章。显然,GWT 不支持不确定的复选框。显然有解决办法。
只要您需要不确定的值,请将复选框设置为空。然后使用 CSS 技巧来设置复选框的样式。
对于 GWT 和 GWT Bootstrap,复选框是一个跨度,其第一个元素是输入复选框。所以问题是这样解决的:
import com.google.gwt.dom.client.Element;
Element element = checkbox.getElement ();
Element child = element.getFirstChildElement ();
if (child != null)
element = child;
setIndeterminate (element, indeterminate);
我希望能够在 GWT 中将 Bootstrap 复选框设置为 "indeterminate" 状态。我写了下面的代码:
/**
* JavaScript to give an ID'd element in a form the focus
*
* @param checkbox Element to manipulate
* @param indeterminate True if indeterminate, false if not
*/
public static native void setIndeterminate (Element checkbox, boolean indeterminate) /*-{
checkbox.indeterminate = indeterminate;
}-*/;
运行 this in Chrome 调试器告诉我复选框设置为 indeterminate = true,但它仍然显示为未选中。当我显示 this page 时,我正确地看到了不确定的复选框,所以这不是浏览器问题。
关于如何解决这个问题有什么建议吗?
为什么需要 JSNI 代码?
您可以使用以下
Checkbox checkbox = new Checkbox("Some-Label");
checkbox.getElement().setAttribute("indeterminate", true /*Or false*/);
编辑
刚刚查看了一些文档和博客文章。显然,GWT 不支持不确定的复选框。显然有解决办法。
只要您需要不确定的值,请将复选框设置为空。然后使用 CSS 技巧来设置复选框的样式。
对于 GWT 和 GWT Bootstrap,复选框是一个跨度,其第一个元素是输入复选框。所以问题是这样解决的:
import com.google.gwt.dom.client.Element;
Element element = checkbox.getElement ();
Element child = element.getFirstChildElement ();
if (child != null)
element = child;
setIndeterminate (element, indeterminate);