<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??一站式輕松地調用各大LLM模型接口,支持GPT4、智譜、豆包、星火、月之暗面及文生圖、文生視頻 廣告
                REST API包含一個JavaScript / Backbone客戶端庫。 該庫為WP REST API提供了一個界面,為所有展現API模式的端點提供了骨干模型和集合。 ##使用 激活WP-API插件。 直接排隊腳本: ``` wp_enqueue_script( 'wp-api' ); ``` 或作為腳本的依賴: ``` wp_enqueue_script( 'my_script', 'path/to/my/script', array( 'wp-api' ) ); ``` 庫解析根端點(“Schema”)并創建匹配的Backbone模型和集合。 你現在可以有兩個根對象:`wp.api.models`和`wp.api.collections`。 模型和收藏包括: 模型: * Category * Comment * Media * Page * PageMeta * PageRevision * Post * PostMeta * PostRevision * Schema * Status * Tag * Taxonomy * Type * User Collections: * Categories * Comments * Media * PageMeta * PageRevisions * Pages * Posts * Statuses * Tags * Taxonomies * Types * Users 您可以使用這些端點來使用標準的Backbone方法來讀取,更新,創建和刪除項目(獲取,同步,保存和銷毀模型,同步收集)。 您還可以擴展這些對象,使其成為您自己的,并在其上構建您的視圖。 ## Default values 每個模型和集合都包含對其默認值的引用,例如: wp.api.models.Post.prototype.args * author: null * comment_status: null * content: null * date: null * date_gmt: null * excerpt: null * featured_image: null * format: null * modified: null * modified_gmt: null * password: null * ping_status: null * slug: null * status: null * sticky: null * title: null ## 可用的方法 每個模型和集合都包含相應端點支持的方法列表。 例如,從`wp.api.models.Post`創建的模型有一個方法數組: ``` ["GET", "POST", "PUT", "PATCH", "DELETE"] ``` ## 接受的選項 每個模型和集合包含相應端點接受的選項列表(注意,在創建模型或集合時,選項作為第二個參數傳遞),例如: ``` wp.api.collections.Posts.prototype.options * author * context * filter * order * orderby * page * per_page * search * status ``` ## 本地化API模式 客戶端將接受并使用本地化模式作為“wpApiSettings”對象的一部分。 默認情況下,模式目前不會傳遞; 而是客戶端向API加載ajax請求以加載模式,然后將其緩存到瀏覽器的會話存儲中(如果可用)。 啟用啟用了“SCRIPT_DEBUG”的client-js插件使用本地化的模式。 檢查[client-js示例](https://github.com/WP-API/client-js/blob/master/client-js.php)或者這個分支,它試圖只將每個客戶端的模式本地化一次。 (https://github.com/WP-API/client-js/compare/features/only-localize-schma-once?expand=1)。 ## 等待客戶端加載 客戶端啟動是異步的。 如果api模式是本地化的,客戶端可以立即啟動; 如果客戶端不是ajax請求來加載模式。 客戶端公開了一個負擔承諾,提供可靠的等待,等待客戶端準備好: ``` wp.api.loadPromise.done( function() { //... use the client here } ) ``` ## 模型示例: 要創建一個帖子并修改其類別,請確保您已登錄,然后: ``` // Create a new post var post = new wp.api.models.Post( { title: 'This is a test post' } ); post.save(); // Load an existing post var post = new wp.api.models.Post( { id: 1 } ); post.fetch(); // Get a collection of the post's categories (returns a promise) // Uses _embedded data if available, in which case promise resolves immediately. post.getCategories().done( function( postCategories ) { // ... do something with the categories. // The new post has an single Category: Uncategorized console.log( postCategories[0].name ); // response -> "Uncategorized" } ); // Get a posts author User model. post.getAuthorUser().done( function( user ){ // ... do something with user console.log( user.get( 'name' ) ); } ); // Get a posts featured image Media model. post.getFeaturedImage().done( function( image ){ // ... do something with image console.log( image ); } ); // Set the post categories. post.setCategories( [ 'apples', 'oranges' ] ); // Get all the categories var allCategories = new wp.api.collections.Categories() allCategories.fetch(); var appleCategory = allCategories.findWhere( { slug: 'apples' } ); // Add the category to the postCategories collection we previously fetched. appleCategory.set( 'parent_post', post.get( 'id' ) ); // Use the POST method so Backbone will not PUT it even though it has an id. postCategories.create( appleCategory.toJSON(), { type: 'POST' } ); // Remove the Uncategorized category postCategories.at( 0 ).destroy(); // Check the results - re-fetch postCategories = post.getCategories(); postCategories.at( 0 ).get( 'name' ); // response -> "apples" ``` ## 集合示例: 得到最后10個帖子: ``` var postsCollection = new wp.api.collections.Posts(); postsCollection.fetch(); ``` 獲取最后25個帖子: ``` postsCollection.fetch( { data: { per_page: 25 } } ); ``` 使用過濾器更改訂單和orderby選項: ``` postsCollection.fetch( { data: { 'filter': { 'orderby': 'title', 'order': 'ASC' } } } ); ``` 所有收藏都自動支持分頁,您可以使用`more`獲得下一頁結果: ``` postsCollection.more(); ``` 獲取一個集合的第5頁: ``` posts.fetch( { data: { page: 5 } } ); ``` 檢查收集是否有更多的帖子: ``` posts.hasMore(); ``` ## 使用修訂 您可以使用PostRevisions或PageRevisions集合或通過Post或頁面集合訪問帖子或頁面修訂。 例如,要獲取所有版本的帖子ID 1的集合: ``` var revisions = new wp.api.collections.PostRevisions({}, { parent: 1 }); ``` 修訂集合也可以通過父母的收藏進行訪問。 這個例子使得2個HTTP請求而不是一個HTTP請求,但現在可以使用原始帖子及其修訂版本: ``` var post = new wp.api.models.Post( { id: 1 } ); post.fetch(); post.getRevisions().done( function( revisions ){ console.log( revisions ); }); ``` 如果您將自定義端點添加到api,它們也將作為模型/集合使用。 例如,當您[為您的自定義帖子類型添加REST API支持](http://v2.wp-api.org/extending/custom-content-types/)時,您將獲得新的模型和集合。 注意:由于模式存儲在用戶的會話緩存中以避免重新獲取,因此您可能需要打開一個新的選項卡才能對Schema進行新的讀取。
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看