Nitrogen get content of table -


so, have nitrogen page, index.erl, contains codes this:

body() ->   [#table{      id = mytable,      rows=[            #tablerow{               cells=[#tableheader{text="column a"},                      #tableheader{text="column b"},                      #tableheader{text="column c"},                      #tableheader{text="column d"}]              },            #custom_row{ %% wrapper around #tablerow               column_a = "a",               column_b = "b",               column_c = "c",               column_d = "d"              }            %% ... more #custom_rows omitted           ]      },    #button{text="submit", postback=store_table}   ].  event(store_table) ->   tabledata = something_like_queryselector(mytable),   insert_into_database(tabledata). 

how content of mytable, nitrogen has queryselector?

there isn't nice , clean queryselector, possible retrieve contents of arbitrary dom element though use of nitrogen's #api{} action.

using code above, following:

body() ->   wf:wire(#api{name=send_table_contents, tag=some_tag}),   [#table{      id = mytable,      rows=[            #tablerow{               cells=[#tableheader{text="column a"},                      #tableheader{text="column b"},                      #tableheader{text="column c"},                      #tableheader{text="column d"}]              },            #custom_row{ %% wrapper around #tablerow               column_a = "a",               column_b = "b",               column_c = "c",               column_d = "d"              }            %% ... more #custom_rows omitted           ]      },    #button{text="submit", click="page.send_table_contents(objs('mytable').html())"}   ].  api_event(send_table_contents, some_tag, [tablehtml]) ->   insert_into_database(tablehtml). 

it's not clean being able request contents can wf:q, job done.

the quick explanation here #api{} action creates new function on page called page.api_name_attribute (so if above, you'll see name attribute send_table_contents , javascript function called in #button.click send_table_contents. contents captured in api_event(nameofapi, tag, listofargs) postback function.

that said, i've added feature to-do list because seems useful thing.


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -