3

如何解析 a Nested ObjectArrayorObjectArray Tree递归函数,以及如何获取每个节点/光标?

我正在解析它并创建一个有组织的结构,然后……使用它。

我的 ObjectArray 树是这样的:

 object(stdClass)[248]
   'id' => int 0
   'type' => string 'root' (length=4)
   'related_dropzone_id' => int 0
   'related_dropzone_order' => int 0
   'options' => 
    object(stdClass)[250]
   'children' => 
    object(stdClass)[249]
       '1376112098462' => 
        (stdClass)[247]
           'id' => string '1376112098462' (length=13)
           'type' => string 'section' (length=7)
           'related_dropzone_id' => int 0
           'related_dropzone_order' => int 0
           'dropzones' => 
            object(stdClass)[246]
              ...
           'options' => 
            object(stdClass)[245]
              ...
           'children' => 
            object(stdClass)[244]
              ...
       '1376112118210' => 
        object(stdClass)[252]
           'id' => string '1376112118210' (length=13)
           'type' => string 'section' (length=7)
           'related_dropzone_id' => int 0
           'related_dropzone_order' => int 1
           'dropzones' => 
            object(stdClass)[255]
              ...
           'options' => 
            object(stdClass)[253]
              ...
           'children' => 
            object(stdClass)[254]
              ...

它有孩子介绍孩子,其中包含对我有效的信息,我需要解析它。

这是我的功能代码:

static public function get_content_html_render_LOM( $data_LOM , $handlebars_instance = '' , $template = '' ) {
            static $template_result = ''; // Save the result html always - recursion

            if ( $handlebars_instance == '' || ! ( $handlebars_instance instanceof Handlebars_Engine ) ) {
                Handlebars_Autoloader::register();
                $handlebars_instance = new Handlebars_Engine;
            }
            if ( isset ( $data_LOM->children ) )
                foreach ( $data_LOM->children as $cursor ) {
                    $template_children = self::read_data_file( SpireBuilder::$widgets_dir . $cursor->type . '/templates/front-end.php' , array() );

                    if ( isset($cursor->related_dropzone_id) &&  $cursor->related_dropzone_id == 0 ){
                        $template = $template_children ; // esto tengo que cambiarlo pues cuando llega a un nuevo nodo
                    }

                    // Render template with data
                    if ( ! isset( $cursor->children ) )
                        $template_result = $handlebars_instance->render( $template , $cursor );
                    else {
                        //dropzones = srray vacio
                        // Por cada dropzone del lom hacer un foreach
                             // temporal children = children de childre
                             // ordenado children = ordenar temportal childre

                             // por cada children de este children
                             // si dropne.'i' == children[related dropxzone id]
                              //        dropzone.'í' = templaate childre
                             // si no noop

                        $template_result = $handlebars_instance->render( $template , array( 'options' => $cursor->options , 'dropzones' => array( 'A' => $template_children ) ) );
                        //var_dump($template_result);
                    }
                    self::get_content_html_render_LOM( $cursor , $handlebars_instance , $template_result );
                }

            return $template_result;
        }
4

1 回答 1

5

测试: $result[] = self::get_content_html_render_LOM( $cursor , $handlebars_instance , $template_result );

保存所有返回递归函数。

于 2013-08-12T11:48:33.967 回答