In backbone.js, can a Model be without a URL?

I have an application in which a menu system is dynamically created using the metadata loaded at startup. Based on this data and the menu selection, I need to create a "filter box" where the user can enter search criteria. The "main" view consists of a filter window and a search results panel, where the result is displayed according to their classes.

Can I simulate a filter as a model of Backbone.js? He does not have any data from the backend, since its composition depends entirely on the choice of menu + metadata? For example. when the user selects the "Sales" menu, then the query "Customer order number" may appear in the filter field, while when the user selects "Material" the filter field may ask for something else.

Then I would use this widget as a component of the "main" view, as well as a variety of result views created on the fly. As users make their choices in the menu, this main view will display the existing filter and reprogram and re-display the new one. Other components on the screen may request a filter for their settings.

In the examples that I have seen so far, there is always a URL and server selection, saving, etc. The only example without a URL on the tutorial page says this is an β€œinvented” example. I was wondering if a server provider is needed, and the programming will be populated with gotchas that do not meet this requirement.

Thanks.

+3
source share
2 answers

You may have models without a url property. One of the Backbone building blocks is the Sync object, which will help you when retrieving and clicking data, ideally from / to REST endpoints. To do this, you need to specify where the data will be served, and for this you set the url value in models or collections.

If you do not need communication with the server, but you just want to use the utilities provided by a simple model or collection (for example, event processing, filtering, etc.), you simply do not set the url and you are good (just keep in mind that methods like fetch or save will not work).

+2
source share

Yes, you can also use Backbone for your DOM logic. The model should not present data from the server. Do whatever you like with a few basic Backbone elements, just use them when you feel like it will do great :)

+1
source share

All Articles