The client exposes a load promise for provide a reliable wait to wait for client to be ready: wp. If the api schema is localized, the client can start immediately if not the client makes an ajax request to load the schema. Check the client-js example or this branch which attempts to only localize the schema once per client.Ĭlient startup is asynchronous. Activating the client-js plugin with SCRIPT_DEBUG enabled uses a localized Schema. The Schema is currently not passed by default instead the client makes an ajax request to the API to load the Schema, then caches it in the browser’s session storage (if available). The client will accept and use a localized schema as part of the wpApiSettings object. For example, models created from wp. have a methods array of: Įach model and collection contains a list of options the corresponding endpoint accepts (note that options are passed as the second parameter when creating models or collections), for example: You can also extend these objects to make them your own, and build your views on top of them.Įach model and collection includes a reference to its default values, for example:Įach model and collection contains a list of methods the corresponding endpoint supports. You can use these endpoints as-is to read, update, create and delete items using standard Backbone methods (fetch, sync, save & destroy for models, sync for collections). This book also recommends an application directory structure, which is not typically covered by any of the Backbone.js tutorials. You will now have two root objects available to you: wp.api.models and wp.api.collections. This book includes Backbone.js boilerplate patterns, JavaScript patterns like function currying, mixins, writing modules using Require.js and also testing with QUnit and Sinon.js. The library parses the root endpoint (the ‘Schema’) and creates matching Backbone models and collections. Or as a dependency for your script: wp_enqueue_script( 'my_script', 'path/to/my/script', array( 'wp-api' ) ) ![]() Enqueue the script directly: wp_enqueue_script( 'wp-api' ) ![]() The library provides an interface for the WP REST API by providing Backbone Models and Collections for all endpoints exposed through the API Schema. The REST API includes a JavaScript/Backbone client library.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |