我目前正在开发一个使用API来检索,更新和删除数据的项目.我正在使用的API是prestashop API.因此,在能够检索数据并更新某些项目之后,我偶然发现了一个问题.正如文档中所述,通过API发送和检索的所有数据都是json
和.xml
由于API的某些数据在json返回中具有不同的级别,如@attributes和@associations级别,我提出了这个问题.
问题是我想访问这些数据,并结合angularjs我想显示这些数据.所以,让我向您展示一个我正在努力实现的快速示例.
首先,JSON
回报将是这样的.
{"products":{"product":[{"id":"1","id_manufacturer":"1","id_supplier":"1","id_category_default":"5","new":{},"cache_default_attribute":"1","id_default_image":"1","id_default_combination":"1","id_tax_rules_group":"1","position_in_category":"0","manufacturer_name":"Fashion Manufacturer","quantity":"0","type":"simple","id_shop_default":"1","reference":"demo_1","supplier_reference":{},"location":{},"width":"0.000000","height":"0.000000","depth":"0.000000","weight":"0.000000","quantity_discount":"0","ean13":"333456789111","isbn":{},"upc":{},"cache_is_pack":"0","cache_has_attachments":"0","is_virtual":"0","state":"1","on_sale":"0","online_only":"0","ecotax":"0.000000","minimal_quantity":"1","price":"16.510000","wholesale_price":"4.950000","unity":{},"unit_price_ratio":"0.000000","additional_shipping_cost":"0.00","customizable":"0","text_fields":"0","uploadable_files":"0","active":"1","redirect_type":"404","id_type_redirected":"0","available_for_order":"1","available_date":"0000-00-00","show_condition":"0","condition":"new","show_price":"1","indexed":"1","visibility":"both","advanced_stock_management":"0","date_add":"2017-03-16 14:36:24","date_upd":"2017-12-01 13:01:13","pack_stock_type":"3","meta_description":{"language":{"@attributes":{"id":"1"}}},"meta_keywords":{"language":{"@attributes":{"id":"1"}}},"meta_title":{"language":{"@attributes":{"id":"1"}}},"link_rewrite":{"language":"gebleekte-T-shirts-met-korte-mouwen"},"name":{"language":"Gebleekte T-shirts met Korte Mouwen"},"description":{"language":"
Fashion maakt goed ontworpen collecties sinds 2010. Het merk biedt vrouwelijke combineerbare kleding en statement dresses en heeft een pr\u00eat-\u00e0-porter collectie ontwikkeld met kledingstukken die niet in een garderobe mogen ontbreken. Het resultaat? Cool, gemakkelijk, easy, chique met jeugdige elegantie en een duidelijk herkenbare stijl. Alle prachtige kledingstukken worden met de grootste zorg gemaakt in Itali\u00eb. …
Run Code Online (Sandbox Code Playgroud) 我目前正在开发一个自定义WordPress模板.在这个模板中,我试图显示特定类别的所有帖子,将其视为一种产品细分(没有销售或任何东西).所以我现在所拥有的是动态显示所有帖子图像和标题,所有样式和过滤ACF的设置.
我想要实现的是以下结果:(使用bootstrap).
每行4列,但有超过4个帖子.(因此,当需要特定类别的第二行或第三行时),创建用于显示帖子5的折叠功能.
经过一番尝试,我得出的结论是,最好的方法是创建一个for循环,结合过滤,这将创建我正在尝试创建的视图.可悲的是,在尝试了一些不同的方法后,我有点卡住了.代码如下所示:
<div id="items">
<?php
if (have_rows('products_category')) {
while (have_rows('products_category')) : the_row();
// Your loop code
$title = get_sub_field('product_category_name');
$slug = get_sub_field('product_category_slug');
/* Start the filter categpries segment */
$category = get_category_by_slug($slug);
$filter_id = $category->term_id;
$filters = array();
var_dump($filters);
array_push($filters, $filter_id);
var_dump($filters);
array_push($filters, 7);
var_dump($filters);
?>
<div id="items" class="row products margin-0 justify-content-between">
<div class=" <?php echo $filter_id ?> ">
<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12 padding-0 padding-b-10">
<h2><?php echo $title ?></h2>
</div>
<div class="col-lg-12 padding-0">
<div id="products" …
Run Code Online (Sandbox Code Playgroud) 对于使用我一直在创建的API的数据的自定义AngularJS应用程序,我遇到了使用Angular双簧管的问题.Oboe是一个bower包,可帮助将大型JSON文件流式传输到视图中.经过一些试验和错误后,我设法建立了一个体面的双簧管GET
方法,在大约2秒内获得大约4000个JSON项目.但是在向GET
同一视图添加更多方法时我的问题就出现了.
起初没有任何问题,但最终,加载时间越来越大.所以我尝试过使用Oboe Cached: true
配置.可悲的是,它根本不起作用.每次加载页面时,所有数据都会再次加载而不是从中获取browser Cache
在下面的例子中,你可以看到我一直试图缓存的一个双簧管函数的结构.下面还添加了一个JSfiddle链接.
功能和视图
function createProduct(id, name) {
this.id = id;
this.name = name;
}
$scope.products = [];
oboe({
url: 'config/get/getProducts.php',
method: 'GET',
cached: true
}).path('products.product.*', function () {
// we don't have the person's details yet but we know we
// found someone in the json stream. We can eagerly put
// their div to the page and then fill it with whatever
// other data we find: …
Run Code Online (Sandbox Code Playgroud)不久前,我开始了一个新的Wordpress项目。但是我遇到了一个问题。由于存在多种设计,因此我需要为不同页面模板上的页面,帖子和文本格式输出创建多个模板。
因此,由于模板文件太多,因此我想创建一些子目录。我知道自Wordpress 3.4及更高版本起,您就可page-templates
以为所有页面模板使用子目录名称,但是我如何将其用于格式文件和发布文件。
是的,我确实尝试添加以下功能:
get_template_part('/template-parts/page-templates' , 'page');
Run Code Online (Sandbox Code Playgroud)
和
require( get_template_directory() . '/template-parts/template-tags.php' );
Run Code Online (Sandbox Code Playgroud)
我要创建的理想目录结构如下:
wp-content/themes/mytheme
- archive
- 404
- CSS
- JS
- Images
- template-parts (dir)
-- page-templates (dir for page-template files.)
-- format-templates (dir for format-templates.)
-- post-templates (dir for post-templates.)
- header
- footer
Run Code Online (Sandbox Code Playgroud)
所以要明确。我想为上述模板文件创建结构。不要介意诸如此类的文件夹CSS
。这些文件夹设置正确。目的是在我成功创建结构之后,能够从/wp-admin
编辑页面部分中选择模板,例如页面模板。
angularjs ×2
javascript ×2
json ×2
php ×2
wordpress ×2
for-loop ×1
function ×1
html ×1
oboe.js ×1
prestashop ×1
subdirectory ×1
templates ×1
web-services ×1