[Developers] multiple mjt queries

Nick Shapiro nick at metaweb.com
Fri Nov 9 01:16:08 UTC 2007


I just spoke with Nick Thompson about this. He says the key is that mjt.run (or mjt.load()) returns a namespace where all the mjt.def functions are available. Once you grab that you can refer to the template function using mjt.run() or other tools, as documented here: http://mjtemplate.org/tour/intro.html#mjt-run-element-template-function-template-args



For example:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8"></meta>
  <script type="text/javascript"
        src="http://mjtemplate.org/dist/mjt-0.5/mjt.js"></script>

<script type="text/javascript">
function init() {
    window.newNamespace = mjt.run('top');
    mjt.run('displaymembers', window.newNamespace.getmembers, ["/freebase/mwstaff"]);
};
</script>
</head>

<body onload="init()">
<div id="top" style="display:none">
  <div id="displaymembers">
  </div>
    <div mjt.def="getmembers(groupId)"> <!-- begin function -->
      <div mjt.task="query">
        mjt.mqlread({
          "type":"/type/usergroup",
          "id":groupId,
          "member":[{
            "id":null
          }]
        })
      </div>
      <div mjt.choose="query.state" mjt.strip="1">
        <div mjt.when="ready" mjt.strip="1"> <!-- process results -->
          <div mjt.for="member in query.result.member">
            $member.id
          </div>
        </div>
        <div mjt.when="wait" mjt.strip="1">
          <div class="loadingMsg">loading report...</div>
        </div>
        <div mjt.when="error" mjt.strip="1">
          Error
        </div>
      </div><!-- finish choose=query.state -->
    </div> <!-- finish function -->
</div><!-- close top div-->
</body>
</html>




More information about the Developers mailing list