在配置中使用loadNetzkeComponent的参数

Use params of loadNetzkeComponent in configuration

本文关键字:loadNetzkeComponent 参数 配置      更新时间:2023-09-26

是否可以将额外的参数传递给"loadNetzkeComponent";并在组件配置中使用它们?

示例:

JavaScript:
this.loadNetzkeComponent({name: 'Erp::OrderPanel', container: 'workspace', params: { orderId: 1 }, scope: this });
Ruby:
class Erp::OrderPanel < Netzke::Base
  # ...
  def configuration(params)
    super.merge(
      scope: { order_id: params[:order_id] }
    )
  end
  # ...
end

我知道,configuration方法没有param属性,但有这样的方法吗?

您可以使用会话(或component_session)存储将参数传递给配置。

session[:order_id] = params[:order_id]

然后在配置中:

def configuration(params)
    super.merge(
      scope: { order_id: session[:order_id] }
    )
  end

1)因为直接从JavaScript传递配置参数是不安全的,所以一种方法是覆盖父组件(调用loadNetzkeComponent的组件)中的delivery_component端点,在那里您可以对传递的参数进行最终的安全检查,然后覆盖组件配置。可以在netzke-core的测试应用程序中找到一个例子:https://github.com/nomadcoder/netzke-core/blob/master/test/core_test_app/app/components/component_loader.rb#L98

2) Dmytro建议的方法可能需要在加载子组件之前对父组件进行额外的端点调用。在该端点中,您将在会话中存储require param-通过这种方式,您将确保每次加载的子组件与服务器通信时都会记住param。第一个方法没有提供这一点,因为传递的参数只使用一次——在加载组件的时候——然后"忘记"。

根据您的要求,从两者中选择一个。

相关文章:
  • 没有找到相关文章