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

Re: DataSource dot notation does not work - bug in YUI 2.6.0

Expand Messages
  • jennykhan
    Hi Jesper, Thanks for the post and for the bug report. While it is true that dot notation access to nested data objects in DataSource has been simplified for
    Message 1 of 2 , Dec 1, 2008
    • 0 Attachment
      Hi Jesper,

      Thanks for the post and for the bug report. While it is true that
      dot notation access to nested data objects in DataSource has been
      simplified for the sake of performance and security, I am unable to
      see the failure case according the information you have provided:

      <div id="test"></div>

      var data = { "data": [ { "id": 1000, "prognose":
      { "situatieDuidelijk": true, "van":
      "ASD", "tot": "RTD" } } ] };

      var ds = new YAHOO.util.LocalDataSource(data);
      ds.responseType = YAHOO.util.DataSource.TYPE_JSON;
      ds.responseSchema = {
      resultsList: "data",
      fields: [
      "id",
      "prognose.situatieDuidelijk",
      "prognose.van",
      "prognose.tot"
      ]
      };

      var cols = [
      {key:"id"},
      {key:"prognose.situatieDuidelijk"},
      {key:"prognose.van"},
      {key:"prognose.tot"}
      ];

      var dt = new YAHOO.widget.DataTable("test", cols, ds);



      If you do need to preserve the object structure of "prognose", I
      recommend defining that at the DataSource field level and using a
      custom formatter to access the object's properties:

      var data2 = { "data": [ { "id": 1000, "prognose":
      { "situatieDuidelijk": true, "van":
      "ASD", "tot": "RTD" } } ] };

      var ds2 = new YAHOO.util.LocalDataSource(data2);
      ds2.responseType = YAHOO.util.DataSource.TYPE_JSON;
      ds2.responseSchema = {
      resultsList: "data",
      fields: [
      "id",
      "prognose"
      ]
      };

      var myFormatter = function(elCell, oRecord, oColumn, oData) {
      elCell.innerHTML = oRecord.getData("prognose")[oColumn.key];
      };

      var cols2 = [
      {key:"id"},
      {key:"situatieDuidelijk", formatter: myFormatter},
      {key:"van", formatter: myFormatter},
      {key:"tot", formatter: myFormatter}
      ];

      var dt2 = new YAHOO.widget.DataTable("test2", cols2, ds2);




      With the caveat that not necessarily every syntax can be supported
      at this time, if you have a valid reproducible error case with
      expected/actual behavior details, it would be helpful to provide it
      for further debugging.

      Regards,
      Jenny



      --- In ydn-javascript@yahoogroups.com, "Jesper" <jespdj@...> wrote:
      >
      > I discovered a serious bug in YUI 2.6.0.
      >
      > According to the documentation of DataSource, you can use dot
      notation
      > in the responseSchema, when you have nested objects in the results.
      > However, this does not work properly.
      >
      > I have submitted a bug report:
      > https://sourceforge.net/tracker/index.php?
      func=detail&aid=2349834&group_id=165715&atid=836476
      >
      > The problem comes down to the following. The author of the current
      > code thought that you can do this in JavaScript:
      >
      > var obj = {};
      >
      > var key = "hello.world";
      > obj[key] = 123;
      >
      > // What does this show?
      > alert(obj.hello.world);
      >
      > This does not show "123" in the alert - instead, it
      shows "undefined".
      > That is because obj["hello.world"] is not the same as
      obj.hello.world.
      > The notation obj["hello.world"] creates a property with the name
      > "hello.world" (with the dot!) in obj - I could see this by
      debugging
      > the code with Firebug. It does not create a property "hello" with
      > another property "world" inside.
      >
      > You can see this bug in datasource-debug.js in lines 1550 and 1555,
      > and the same mistake is possibly made in other places (line 1573?).
      >
      > Because of this, nested objects and dot notation (and also notation
      > with brackets) does not work with DataSource at the moment. I hope
      > this bug can be fixed soon.
      >
    Your message has been successfully submitted and would be delivered to recipients shortly.