在XUL中捕获可编辑的树更改 [英] Capture editable tree changes in XUL

查看:98
本文介绍了在XUL中捕获可编辑的树更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个动态构造的可编辑XUL树。
问题是-应该如何监听和捕获更改的单元格?

I have a dynamically constructed editable XUL tree. The problem is - how is one supposed to listen and capture the changed cells?

我通过捕获 tree.inputField 的> blur 事件,其他任何事件均不起作用。
至少行得通,但是有一种简单的方法来获取新值吗?

I detect the submitting of the edited value by capturing blur event of the tree.inputField, any other events are not working. At least it works, but is there an easy way to retrieve new value?

它真的像获取Tree元素,计算当前值一样令人讨厌吗?单元格,并查询它的新值?

Should it really be as hackish as getting the Tree element, calculating the current cell, and querying its new value?

推荐答案

我想动态构建意味着您为树动态生成了DOM元素项目。然后,您应该能够在< treechildren> 标记上注册 DOMAttrModified 事件处理程序,并聆听树单元格的 label 属性。

I guess that "dynamically constructed" means that you dynamically generate DOM elements for the tree items. Then you should be able to register a DOMAttrModified event handler on the <treechildren> tag and listen to changes of the label attribute of the tree cells.

但是,通常的方法是使树完全动态。您需要一个实现 nsITreeView 的对象(请参见 https:// developer.mozilla.org/En/NsITreeView )。您将该对象分配给 tree.view 属性。该对象定义了树有多少行,在哪个单元格中显示什么,行/列/单元格应具有什么属性,而所有这些都没有在< treechildren> 。不幸的是,这是一个难以实现的接口,尤其是由于树的分层性质。如果您的清单很简单,那么许多方法就变得微不足道了。

However, the usual approach is to have the tree entirely dynamic. You need an object implementing nsITreeView (see https://developer.mozilla.org/En/NsITreeView). You assign that object to the tree.view property. And that object defines how many rows your tree has, what to display in which cell, what properties a row/column/cell should have, all without having any DOM nodes inside <treechildren>. Unfortunately, it is a complicated interface to implement, especially because of the hierarchical nature of the trees. If you have a plain list many methods become trivial however.

两种方法特别有趣。 isEditable()允许您确定特定树单元是否应可编辑。每当编辑单元格时,就会调用 setCellText()

Two methods are particularly interesting. isEditable() allows you to determine whether a particular tree cell should be editable. And setCellText() is called whenever a cell has been edited.

如果不想重新实现nsITreeView ,也应该可以包装默认视图。像这样:

If you don't want to reimplement nsITreeView, wrapping the default view should also be possible. Something like this:

var oldView = tree.view;
var newView = {
    __proto__: oldView,
    setCellText(row, col, value)
    {
        oldView.setCellText(row, col, value);
        alert("Text changed for a tree cell!");
    }
};
tree.view = newView;

这篇关于在XUL中捕获可编辑的树更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆