Loading ...
Sorry, an error occurred while loading the content.

Help with schema for autocomplete?

Expand Messages
  • Zach Copley
    Hey guys, Here s something I m not clear on. Do I have to have my data returned in JSON in the ResultSet.Result format? Or can I another simpler format?
    Message 1 of 2 , May 30, 2008
    • 0 Attachment
      Hey guys,

      Here's something I'm not clear on. Do I have to have my data returned in JSON in the
      ResultSet.Result format? Or can I another simpler format? Here's what my json looks like
      (just a couple example records):

      --->8---
      [{"Product":{"id":"1","title":"How to have fun in the
      sun","search_alias":"CACI"}},{"Product":{"id":"2","title":"How to escape
      zombies","search_alias":"CCOR"}}]<!-- 0.479s -->
      --->8---

      Now how do I define the schema for that? Here's what I have for my autocomplete js...

      -->8---
      <div id="parentAutoComplete">
      <input id="parent" type="text" size="100">
      <div id="parentContainer"></div>
      <input type="button" id="setParent" name="setParent" value="Set">
      </div>
      <script type="text/javascript">

      var server = "/production/Products/product_list.json";
      var schema = ["Product", "id", "title", "search_alias"];
      var parentDataSource = new YAHOO.widget.DS_XHR(server, schema);


      var myAutoComp = new YAHOO.widget.AutoComplete("parent", "parentContainer",
      parentDataSource);

      </script>
      --->8---

      And, of course, it doesn't work. BTW, should I install the YUI logging stuff to help debug
      this kind of thing?

      Thanks for your help in advance!

      Zach
    • Zach Copley
      Okay, I m going to go ahead and answer my own question in hopes that it helps someone else... ... like ... Answer: I don t think you can. The autocomplete
      Message 2 of 2 , Jun 5, 2008
      • 0 Attachment
        Okay, I'm going to go ahead and answer my own question in hopes that it helps someone
        else...

        --- In ydn-javascript@yahoogroups.com, "Zach Copley" <a_czech_ploy@...> wrote:
        >
        > Hey guys,
        >
        > Here's something I'm not clear on. Do I have to have my data returned in JSON in the
        > ResultSet.Result format? Or can I another simpler format? Here's what my json looks
        like
        > (just a couple example records):
        >
        > --->8---
        > [{"Product":{"id":"1","title":"How to have fun in the
        > sun","search_alias":"CACI"}},{"Product":{"id":"2","title":"How to escape
        > zombies","search_alias":"CCOR"}}]<!-- 0.479s -->
        > --->8---
        >
        > Now how do I define the schema for that?

        Answer: I don't think you can. The autocomplete component wants object notation for the
        schema attribute. You can't just send the component a bunch of randomly json-ified data.
        You need to send an object tree. In fact, it's probably safest just to stick with the
        ResultSet.Result format. There aren't any examples around showing how to use the
        autocomplete component with a different schema (that I could find), and I had no luck
        experimenting with different object structures. But once I formatted my JSON data like the
        examples (ResultSet.Result), everything worked like a charm.

        > And, of course, it doesn't work. BTW, should I install the YUI logging stuff to help
        debug
        > this kind of thing?

        Yes, the Logger is fantastic for this! It's an amazingly great debugging tool for YUI events
        and stuff, especially for server-side interaction. Duh!

        Zach
      Your message has been successfully submitted and would be delivered to recipients shortly.