0

如何从 PHP 中的 GtkTreeView 检索行数据?

我的尝试:

// $this->guidata = new GtkListStore();
// $this->view = new GtkTreeView($this->guidata);

$dutarray = array();

$selection = $this->view->get_selection();
$selection->select_all();

$dutArray = $selection->get_selected_rows();

谢谢你的帮忙!

迎接 leon22

PS:我有一个包含 2 列和 n 行的表(使用 $this->guidata->append($row) 添加行)

4

1 回答 1

0

迭代通过 GtkListStore 而不是 GtkTreeView!使用此代码,您可以从列表中检索值!

    $this->dutArray = array();      
    $iter = $this->guidata->get_iter_first();

    //$iterIndex = 1;
    while (null != $iter)
    {   
        $key = $this->guidata->get_value($iter, 0);
        $value = $this->guidata->get_value($iter, 1);

        $this->dutArray = $this->array_push_assoc($this->dutArray, $key, $value);

        $iter = $this->guidata->iter_next($iter); // incement iterator                                  
    }   

能够将键/值对添加到数组的函数

    public function array_push_assoc($array, $key, $value)
    {
        $array[$key] = $value;  
        return $array;
    }
于 2012-01-25T12:43:50.837 回答