Question

I am new to web programming and of course to YUI.

I tried using the overlay, chart and node-menunav. Wanted to know if there is any option of creating these widgets using dynamic data coming in JSON format and updating the widgets as the new data comes in?

For us all the properties will come in JSON data from server and then using that data we need to render menubars, charts, property browser. Now i am not finding how to proceed with this requirement.

Thanks.

Était-ce utile?

La solution

There is no default way of syncing widgets via Ajax. The only widget that comes by default with ways of updating its data is the DataTable widget. For the rest, and even for DataTable's attributes, you need to do it yourself.

However, if the data and widgets are complicated enough, you should consider using the YUI App Framework. The combination of Models and Views will help you a lot for creating complex layouts with widgets. Model will give you a way to link attributes to a JSON backend easily, specially if you're using a RESTful API endpoint. And View will give you tools for setting up the markup and reacting to events.

The Model's load and change events will let you know when the data updates. So in your view you'll be able to react to these events and set the corresponding attributes in your widgets:

var MyView = Y.Base.create('myView', Y.View, [], {
  initializer: function () {
    this.get('model').on('change', this._updateWidgets, this);
  },
  _updateWidgets: function () {
    var model = this.get('model');
    this.someWidget.set('someAttr', mode.get('someAttr'));
  }
});

But as I said there is no right way of doing this. You can use whatever technique you like. The App framework is just a set of basic components that you can use to structure you application. It's designed for flexibility so it can accommodate many ways of using it. Other ways could use IO directly or use DataSources combined with Widget Plugins. This is a question with many correct answers.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top