Kendo React TreeView 复选框不起作用

huangapple go评论49阅读模式
英文:

Kendo React TreeView CheckBox not working

问题

勾选 TreeView 中的复选框无法正常工作。

这是代码部分。带有复选框节点的 Treeview 在扩展面板内。

<ExpansionPanel
  className='item-body-dropDownList'
  title={"Expension panel"}
  expanded={expanded === item.id}
  tabIndex={0}
  key={item.id}
  onAction={(event) => {
    setExpanded(event.expanded ? "" : item.id);
  }}
>
  <Reveal>
    {expanded === item.id && (
      <ExpansionPanelContent>
        <TreeView
          data={processTreeViewItems(tree, {
            check: check,
          })}
          checkboxes={true}
          onCheckChange={onCheckChange}
        />
      </ExpansionPanelContent>
    )}
  </Reveal>
</ExpansionPanel>

树数据:

const tree = [
  {
    text: "Item1",
  },
  {
    text: "Item2",
  },
];

onCheckChange 函数:

const onCheckChange = (event) => {
  const settings = {
    singleMode,
    checkChildren,
    checkParents,
  };
  setCheck(handleTreeViewCheckChange(event, check, tree, settings));
};

我尝试从这个网站 https://www.telerik.com/kendo-react-ui/components/treeview/checkboxes/ 实现 TreeView,但它不起作用。

请帮助一下?

英文:

Checking CheckBox inside TreeView is not working.

Kendo React TreeView 复选框不起作用

This is the code. Treeview with CheckBox nodes inside expansion panel.

&lt;ExpansionPanel
          className=&#39;item-body-dropDownList&#39;
          title={&quot;Expension panel&quot;}
          expanded={expanded === item.id}
          tabIndex={0}
          key={item.id}
          onAction={(event) =&gt; {
            setExpanded(event.expanded ? &quot;&quot; : item.id);
          }}
        &gt;
          &lt;Reveal&gt;
            {expanded === item.id &amp;&amp; (
              &lt;ExpansionPanelContent&gt;
                &lt;TreeView
                data={processTreeViewItems(tree, {
                  check: check,
                })}
                checkboxes={true}
                onCheckChange={onCheckChange}
              /&gt;
              &lt;/ExpansionPanelContent&gt;
            )}
          &lt;/Reveal&gt;
        &lt;/ExpansionPanel&gt;

Tree data

const tree = [
    
    {
      text: &quot;Item1&quot;,
    },
    {
      text: &quot;Item2&quot;,
    },
  ];

onCheckChange

const onCheckChange = (event) =&gt; {
          const settings = {
            singleMode,
            checkChildren,
            checkParents,
          };
          setCheck(handleTreeViewCheckChange(event, check, tree, settings));
        };

I tried to implement TreeView from this web cite https://www.telerik.com/kendo-react-ui/components/treeview/checkboxes/ but its not working.

Any help please?

答案1

得分: 1

你可以在这里看到TreeView的示例实现 - https://codesandbox.io/s/rpkns2?file=/app/main.jsx

而且代码的更多细节将有助于更好地调试此问题。

例如,此方法的实现 - onCheckChange
以及组件ExpansionPanel,Reveal,ExpansionPanelContent

英文:

you can see sample implementation of TreeView from here - https://codesandbox.io/s/rpkns2?file=/app/main.jsx

And some more details of the code would help more to debug this issue.

for ex. the implementation of this method - onCheckChange
and also the components ExpansionPanel, Reveal, ExpansionPanelContent

答案2

得分: 0

我解决了这个问题。我的全局 CSS 覆盖了 CheckBox 的背景颜色,所以我只是改变了背景颜色。

英文:

I solved the problem. My global CSS was overriding background-color of the CheckBox, so I just changed the background-color.

huangapple
  • 本文由 发表于 2023年7月20日 22:34:07
  • 转载请务必保留本文链接:https://go.coder-hub.com/76730974.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定