API version 1
- ‐
findItems¶
子・子孫のツリーアイテムを検索し、発見したすべてのアイテムを取得します。
選択されたツリーアイテムの子・子孫から指定された条件に合うものを検索し、発見した全てのアイテムをArrayオブジェクトに格納して返します。
発見できなかった場合は要素数0のArrayオブジェクトを返します。
引数をすべて省略した場合、すべての子・子孫アイテムをArrayオブジェクトに格納して返します。
呼出形式一覧
呼出形式 |
説明 |
---|---|
CRS::Common::UI::TreeItem[] findItems([primitive data[, integer option]]) |
optionで指定されるプロパティを対象に、条件dataに合う子・子孫のツリーアイテムを検索します。 |
戻り値一覧
戻り値 |
説明 |
---|---|
CRS::Common::UI::TreeItem[] |
検索条件に合うツリーアイテムのArrayオブジェクト。 |
引数一覧
引数 |
説明 |
||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
data |
検索条件のデータを指定します。 |
||||||||||
option |
検索対象のプロパティを指定します。 以下の定数を組み合わせて指定します。省略時はFIND_VALUEです。
|
例外
なし
関連項目
findItemメソッド
使用例
CRSダウンロード
Form TreeItem_findItem {
x = 0;
y = 0;
width = 1247;
height = 826;
function printItem(item, prefix)
{
var str = prefix + " id=";
if (item.id == null) {
str += "(null)";
} else {
str += item.id.toString();
if (item.id != 0) {
str += ", title: " + item.title + ", value=" ;
var value = item.value;
str += (value != null) ? value.toString() : "(null)";
}
}
print(str);
}
TreeView treeView1 {
x = 8;
y = 8;
width = 640;
height = 480;
function onClicked(e) {
if (e.item == null) {
print("空白エリアがクリックされました");
return;
}
print("TreeItem(id=",str(e.item.id) ,", title=", e.item.title, ", value=", e.item.value,") がクリックされました。");
};
function initializeTree(numDescendants)
{
var treeItems = new Array(numDescendants);
treeItems[0] = rootItem;
for (var index = 0; index < numDescendants; index ++) {
var parentItem = treeItems[Math.floor(Math.random() * index)];
var childTitle = ((parentItem.title == "") ? "item" : parentItem.title) + "-" + str(getNumChildren(parentItem));
treeItems[index + 1] = parentItem.append(childTitle);
treeItems[index + 1].value = Math.floor(Math.random() * 10);
}
}
function getNumChildren(item) {
var numItems = 0;
for (var child = item.child; child != null; child = child.next) {
numItems ++;
}
return numItems;
}
initializeTree(100);
rootItem.expandAll();
}
TextBox textBoxFindItem {
x = 656;
y = 8;
width = 120;
height = 24;
value = "4";
}
Button buttonFindItem {
x = 656;
y = 112;
width = 120;
height = 24;
Title = "FindItem";
function onTouch(e) {
var item = ^.treeView1.selectedItem;
if (item == null) {
print("TreeItem が選択されていないので検索しません");
return;
}
var typesFind = ^.checkBoxFindType.getTypesFind();
var itemFound;
#選択アイテムの子・子孫アイテムのうち、チェックボックスでチェックされた検索対象のデータがtextBoxFindItemの最初のアイテムを取得します
if ( typesFind == 0 ) {
itemFound = item.findItem(^.textBoxFindItem.value);
} else {
itemFound = item.findItem(^.textBoxFindItem.value, typesFind);
}
if (itemFound == null) {
print("findItem: no item found");
return;
}
itemFound.selected = true;
print("findItem: TreeItem(id=" + str(itemFound.id) + ", title=" + itemFound.title + ") が見つかりました");
}
}
Button buttonFindItems {
x = 656;
y = 144;
width = 120;
height = 24;
Title = "FindItems";
function onTouch(e) {
var item = ^.treeView1.selectedItem;
if (item == null) {
print("TreeItem が選択されていないので検索しません");
return;
}
var typesFind = ^.checkBoxFindType.getTypesFind();
var items;
#選択アイテムの子・子孫アイテムのうち、チェックボックスでチェックされた検索対象のデータがtextBoxFindItemのアイテムの配列を取得します
if (typesFind == 0 ) {
items = item.findItems(^.textBoxFindItem.value);
} else {
items = item.findItems(^.textBoxFindItem.value, typesFind);
}
print("findItems: " + str(items.length) + "個の TreeItem が見つかりました");
for (var index = 0; index < items.length; index ++) {
var item = items[index];
print(str(index) + ": TreeItem(id=" + str(item.id) + ", title=" + item.title + ")");
}
}
}
CheckBox checkBoxFindType {
x = 656;
y = 40;
width = 120;
height = 64;
CheckItem items[3] {
Y = 0;
x = 0;
width = 114;
height = 14;
layoutSpacing = 0;
layoutMargin = 0;
items[0].Title = "Find by value";
items[1].Title = "Find by title";
items[2].Title = "Find by id";
}
function getTypesFind() {
var typesFind = 0;
var checkBox = this; # checkBoxFindType;
if (checkBox.items[0].selected) {
typesFind += TreeItem.FIND_VALUE.toInteger();
}
if (checkBox.items[1].selected) {
typesFind += TreeItem.FIND_TITLE.toInteger();
}
if (checkBox.items[2].selected) {
typesFind += TreeItem.FIND_ID.toInteger();
}
return typesFind;
}
}
}