Last active
October 2, 2024 06:40
-
-
Save unixc3t/fb19ee2aef64f6667acc1915fcd01ea5 to your computer and use it in GitHub Desktop.
phoenix component and sloct_demo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use Phoenix.Component | |
import Phoenix.HTML | |
attr :myrows, :list, required: true | |
slot :mycol, required: true do | |
attr :label, :string | |
end | |
def table_1(assigns) do | |
~H""" | |
<%= for col <- @mycol do %> | |
<%= col.label %> | |
<% end %> | |
<%= for my <- @myrows do %> | |
<%= for col <- @mycol do %> | |
<%= render_slot(col, my) %> | |
<% end %> | |
<% end %> | |
""" | |
end | |
def table_2(assigns) do | |
~H""" | |
<%= for col <- @mycol do %> | |
<%= col.label %> | |
<% end %> | |
<.myview myrows={@myrows} mycol={@mycol}> | |
</.myview> | |
""" | |
end | |
def myview(assigns) do | |
~H""" | |
<%= for my <- @myrows do %> | |
<%= for col <- @mycol do %> | |
<%= render_slot(col, my) %> | |
<% end %> | |
<% end %> | |
""" | |
end | |
--------- | |
<DemographicLive.Show.table_1 myrows={@dhello}> | |
<:mycol :let={m} label="Name"> | |
<%= m.name %> | |
</:mycol> | |
<:mycol :let={m} label="Age"> | |
<%= m.age %> | |
</:mycol> | |
</DemographicLive.Show.table_1> | |
<hr/> | |
<DemographicLive.Show.table_2 myrows={@dhello}> | |
<:mycol :let={m} label="Name"> | |
<%= m.name %> | |
</:mycol> | |
<:mycol :let={m} label="Age"> | |
<%= m.age %> | |
</:mycol> | |
</DemographicLive.Show.table_2> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment