古腾堡动态SelectControl值对象

时间:2018-12-11 20:06:28

标签: wordpress wordpress-gutenberg gutenberg-blocks

我想将选项对象动态传递给Gutenberg SelectControl:

select
    r.ctripnumber, sum(Revenue_Subtotal) as 'Revenue Total' 
from 
    (select r.ctripnumber, r.cmethod, sum(r.curevenue) as Revenue_Subtotal
     from revenuedtl r 
     where r.cmethod in (select distinct r.cmethod from revenuedtl r)
     --and r.ctripnumber = '324198'
     group by r.ctripnumber, r.cmethod) A

我有一个PHP函数可以返回可用动画的对象?

el( SelectControl, {
    label: __( 'Animation' ),
    value: props.attributes.animation,
    onChange: ( value ) => { props.setAttributes( { animation: value } ); },
    options: [
      { value: 'date', label: __( 'One column' ) },
      { value: 'title', label: __( 'Two columns' ) },
    ],
  }
),

1 个答案:

答案 0 :(得分:1)

我已经使用 wp_localize_script 将该数组作为JS中的对象:

$variables['animations'] = _functions::_animation();
wp_localize_script( $this->plugin_name, 'meetongo', $variables );

,您可以像这样访问该对象:

console.log( meetongo.animations );