Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/elixir/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/ant/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Elixir 更改集在下拉数据更新时未更新_Elixir_Phoenix Framework_Liveview - Fatal编程技术网

Elixir 更改集在下拉数据更新时未更新

Elixir 更改集在下拉数据更新时未更新,elixir,phoenix-framework,liveview,Elixir,Phoenix Framework,Liveview,假设我有数据: data = [[key: 1, value: "1"], [key: 2, value: "2"] ,[key: 3, value: "3"]] child_data = %{1: [key: 1, value: "exists"]} 以及html: <%= select f, :corporation_id, data %> <%= select f, :company_id,

假设我有数据:

data = [[key: 1, value: "1"], [key: 2, value: "2"] ,[key: 3, value: "3"]]
child_data = %{1: [key: 1, value: "exists"]}
以及html:

<%= select f, :corporation_id, data %>
<%= select f, :company_id, child_data[Ecto.changeset.get_field(@changeset, :corporation_id)] %>
问题如下:当我更改
公司的数据时
变更集没有得到更新,旧的id仍然存在,它仍然是一个有效的变更集。据我所知,发生这种情况是因为在更新数据时没有发出验证事件


这个问题有解决办法吗?

不幸的是,没有JavaScript或凤凰城的新LiveView,您无法完成您想要的任务。 当模板被发送到浏览器时,处理反应性的唯一方法是通过JavaScript。 在您的情况下,您需要做的是将所有子_数据发送到select:
。然后使用JavaScript,您将在公司字段上收听
change
事件,以过滤
child\u数据的值

好的,看起来这是LiveView当前的一个限制。使用JS中的更新钩子,我能够将更新发送到服务器。 钩子:

Hooks.WorkaroundHook = {
  updated() {
    this.pushEvent("workaround", this.el.selectedIndex)
  }
}
手柄:

  def handle_event("workaround", index, socket) do
    # if changeset is valid and index is 0 add error to changeset
    {:noreply, socket}
  end

我已经在使用liveview了,请注意标签
  def handle_event("workaround", index, socket) do
    # if changeset is valid and index is 0 add error to changeset
    {:noreply, socket}
  end