我将NSOutlineView与文本字段/文本字段单元格结合使用,如下图所示:
hierarchically correct main
element
已发送动作函数的代码:
@IBAction func handleTextFieldDidEndEditing(_ sender: Any) {
print("LeftNavBarOutlineView selectedRow: \(self.selectedRow)")
print("LeftNavBarOutlineView editedRow: \(self.editedRow)")
print("LeftNavBarOutlineView selectedRowIndexes.count: \(self.selectedRowIndexes.count)")
let taskName = (sender as! NSTextField).stringValue
print("LeftNavBarOutlineView " + taskName)
}
打印结果:
LeftNavBarOutlineView selectedRow: -1
LeftNavBarOutlineView editedRow: -1
LeftNavBarOutlineView selectedRowIndexes.count: 0
LeftNavBarOutlineView
问题:
“发送者” 对象是一个NSTextField实例。我需要检索我的func outlineView(_ outlineView: NSOutlineView, child index: Int, ofItem item: Any?) -> Any
函数返回的“项目” 。
我要么需要直接获取“ item”,要么需要获得行索引(可以从地图词典中检索“ item”)
由于“发送者”是一个NSTextField,我如何找出刚刚被编辑的行(或“项目”)是什么?
谢谢!
答案 0 :(得分:2)
使用row(for view
获取行,使用item(atRow
获取项目
<script>
$(document).on("click","#user",function(){
load_data();
});
function load_data()
{
$.ajax({
url:"fetch.php",
method:"POST",
success:function(data)
{
$('#user_data').html(data);
}
});
}
<script>
<script type='text/javascript'>
function addFields() {
var number = document.getElementById("member").value;
var container = document.getElementById("container");
var optionsSelect = [
{
id: 1,
title: 'Option 1'
},
{
id: 2,
title: 'Option 2'
},
{
id: 3,
title: 'Option 3'
}
];
while (container.hasChildNodes()) {
container.removeChild(container.lastChild);
}
for (i = 0; i < number; i++) {
var select = document.createElement('select');
for (var j = 0; j < optionsSelect.length; j++) {
var options = document.createElement("option");
options.value = optionsSelect[j].id;
options.text = optionsSelect[j].title;
select.appendChild(options);
}
container.appendChild(select);
container.appendChild(document.createTextNode(" -> Description " + (i + 1) + " "));
var input = document.createElement("input");
input.type = "text";
container.appendChild(input);
container.appendChild(document.createElement("br"));
}
}
</script>
是@IBAction func handleTextFieldDidEndEditing(_ sender: NSTextField) {
let row = outlineView.row(for: sender)
let item = outlineView.item(atRow: row)
实例