Search code examples
javascriptmarklogic

how to retrieve data from a Marklogic database when editing the generated source code?


I want to edit the generated Marklogic source code by adding a select list for restricting search. The generated code is a javascript and the select list should contain information retrieved from the database. I'm new to marklogic and i don't know how do so.

The generated code:

'<form name="query" id="query">'
    + '<input type="text" id="query-text" value="" autocomplete="off" />'
    + '<button type="submit" class="button" id="update- query">Search</button>'
    + '</form>'
    + '<div id="search-suggestions"></div>';

I want to add this code:

     <p>Choose a section: </p>
     <select name="sec-title" id="sec-title">
     <option value="all">all</option>
     {
     for $sec-title in fn:distinct-values(//a:sec-title/text())
     order by $sec-title
     return if($sec-title = xdmp:get-request-field("sec-title"))
     then <option value="{$sec-title}" selected="selected"> {$sec-title}  </option>
     else <option value="{$sec-title}"> {$sec-title} </option>
     }
     </select>

Solution

  • It sounds like you used AppBuilder to make a sample application.

    It should be noted that AppBuilder appears to be deprecated from ML8 onwards in preference of sample applications in Java and node.js. For those, see github for marklogic sample stack.

    Extending AppBuilder Apps
    If you really want to move forward with extending the AppBuilder application, see here.

    Export the original AppBuilder code to edit as you wish
    If you need to move forward with the AppBuilder code, I would suggest that you export the entire application's source code into a local directory and then use this as a base for your application. Then you just start editing as you wish. For this, you would use Roxy(the deployer part) and follow the great set of directions here provided by David Casel