Checkbox 我应该捕获什么事件来捕获XUL树中的复选框更改?

Checkbox 我应该捕获什么事件来捕获XUL树中的复选框更改?,checkbox,tree,xul,Checkbox,Tree,Xul,我有点XUL <?xml version="1.0"?> <?xml-stylesheet href="chrome://global/skin/" type="text/css"?> <?xml-stylesheet href="chrome://zotero-report-customizer/skin/options.css"?> <!DOCTYPE window SYSTEM "chrome://zotero-report-customizer/

我有点XUL

<?xml version="1.0"?>
<?xml-stylesheet href="chrome://global/skin/" type="text/css"?>
<?xml-stylesheet href="chrome://zotero-report-customizer/skin/options.css"?>
<!DOCTYPE window SYSTEM "chrome://zotero-report-customizer/locale/zotero-report-customizer.dtd">
<prefwindow id="zotero-report-customizer-perf" title="&zotero-report-customizer.name;" xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" onload="initializePrefs();">
  <stringbundleset id="stringbundleset">
    <stringbundle id="zotero-report-customizer-options" src="chrome://zotero-report-customizer/locale/options.properties" />
    <stringbundle id="zotero-options" src="chrome://zotero/locale/zotero.properties" />
  </stringbundleset>
  <prefpane label="&zotero-report-customizer.remove;" id="zotero-report-customizer-perfpane">
    <preferences id="preferences"/>
    <groupbox>
      <caption label="&zotero-report-customizer.remove;" />
      <tree flex="1" id="treeCollection" seltype="single" hidecolumnpicker="true" height="400" editable="true" onselect="togglePref(this);">
        <treecols>
          <treecol id="show" primary="true" type="checkbox" label="Show" editable="true" width="40"/>
          <treecol id="field" label="Field" editable="false" flex="1"/>
        </treecols>
        <treechildren id="itemTypes"/>
      </tree>
    </groupbox>
  </prefpane>
  <script src="chrome://zotero/content/include.js" />
  <script src="chrome://zotero-report-customizer/content/include.js" />
  <script src="options.js" />
</prefwindow>


我动态添加带有复选框的树行;他们表现得很好。但是,我用什么“on…”事件来捕捉并注意到正在切换的复选框?Onselect没有做到这一点。

我本来不理解你的问题

不能将事件处理程序添加到树的行/列/单元格,只能添加到
本身。例如:你可以在树上检测到一个“点击”事件——然后你需要弄清楚点击了什么,最后,你应该怎么做

用于从鼠标单击事件获取
的MDN:

XUL:

此时,您应该检查
treeCell
(在
复选框
模式中)是否已选中(或未选中),而不是提醒
单元格文本
,并相应地采取行动

从MDN上的
中释义:

编辑:确保列/单元格标记为可编辑,否则可能无法工作

<tree id="my-tree" onclick="onTreeClicked(event)">
function onTreeClicked(event){
  var tree = document.getElementById("my-tree");
  var tbo = tree.treeBoxObject;

  // get the row, col and child element at the point
  var row = { }, col = { }, child = { };
  tbo.getCellAt(event.clientX, event.clientY, row, col, child);

  var cellText = tree.view.getCellText(row.value, col.value);
  alert(cellText);
}
var cellChecked = tree.view.getCellValue(row.value, col.value) == 'true';