ng-2亲子数据继承对我来说一直是个难题.
看起来可能是一个很好的实用解决方案是将我的整个数据数组过滤到一个数组,该数组只包含由单个父ID引用的子数据.换句话说:数据继承成为一个父ID的数据过滤.
在一个具体的例子中,这可能看起来像:过滤书籍数组只显示具有特定的书籍store_id.
import {Component, Input} from 'angular2/core';
export class Store {
id: number;
name: string;
}
export class Book {
id: number;
shop_id: number;
title: string;
}
@Component({
selector: 'book',
template:`
<p>These books should have a label of the shop: {{shop.id}}:</p>
<p *ngFor="#book of booksByShopID">{{book.title}}</p>
`
])
export class BookComponent {
@Input()
store: Store;
public books = BOOKS;
// "Error: books is not defined"
// ( also doesn't work when books.filter is called like: this.books.filter
// "Error: …Run Code Online (Sandbox Code Playgroud) 在使用Savon.rb的rails项目中,我试图进行一个非常复杂的SOAP调用.至少复杂到Savon构建器的扩展很麻烦所以我决定直接操作:xml.
首先我发起客户:
@client = Savon.client(
:endpoint => 'https://testservice.postnl.com/CIF_SB/BarcodeWebService/1_1/BarcodeWebService.svc',
:wsdl => 'https://testservice.postnl.com/CIF_SB/BarcodeWebService/1_1/?wsdl')
Run Code Online (Sandbox Code Playgroud)
然后我打电话的形状为:
@request = @client.build_request(:generate_barcode,
xml: %Q{ ... see soap call (with ruby interpolation) ... }
Run Code Online (Sandbox Code Playgroud)
我添加了一个格式正确的l Time.now, format: :postnl_api字符串,其余的仍然是硬编码.包括消息号.
以下是Savon在这种情况下实际调用的方式,如使用@request.body.
我的应用程序中的SOAP调用
<?xml version="1.0" encoding="UTF-8"?>
<s:Envelope
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:wsdl="http://tempuri.org/"
xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Header>
<Action s:mustUnderstand="1" xmlns="http://schemas.microsoft.com/ws/2005/05/addressing/none">http://postnl.nl/cif/services/BarcodeWebService/IBarcodeWebService/GenerateBarcode
</Action>
<Security xmlns="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<UsernameToken>
<Username>devc_!R4xc8p9</Username>
<Password>xxxxxxxx</Password>
</UsernameToken>
</Security>
</s:Header>
<s:Body>
<wsdl:GenerateBarcode>
<d6p1:Customer>
<d6p1:CustomerCode>DEVC</d6p1:CustomerCode>
<d6p1:CustomerNumber>11223344</d6p1:CustomerNumber>
</d6p1:Customer>
<d6p1:Barcode>
<d6p1:Type>3S</d6p1:Type>
<d6p1:Range>DEVC</d6p1:Range>
<d6p1:Serie>1000000-2000000</d6p1:Serie>
</d6p1:Barcode>
</wsdl:GenerateBarcode>
</s:Body>
</s:Envelope>
Run Code Online (Sandbox Code Playgroud)
接下来是一个调用应该是什么样子,因为我看到这个调用在公司的沙箱环境中取得了成功.
应该是SOAP调用
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Header>
<Action s:mustUnderstand="1" xmlns="http://schemas.microsoft.com/ws/2005/05/addressing/none">http://postnl.nl/cif/services/BarcodeWebService/IBarcodeWebService/GenerateBarcode</Action>
<Security …Run Code Online (Sandbox Code Playgroud) 遵循此方法:
class ImagesController < ApplicationController
before_action :set_gallery
def create
add_more_images(images_params[:images])
flash[:error] = "Failed uploading images" unless @gallery.save
redirect_to :back
end
def destroy
remove_image_at_index(params[:id].to_i)
flash[:error] = "Failed deleting image" unless @gallery.save
redirect_to :back
end
private
def set_gallery
@gallery = Gallery.find(params[:gallery_id])
end
def add_more_images(new_images)
images = @gallery.images
images += new_images
@gallery.images = images
end
def remove_image_at_index(index)
remain_images = @gallery.images # copy the array
deleted_image = remain_images.delete_at(index) # delete the target image
deleted_image.try(:remove!) # delete image from S3
@gallery.images = remain_images # …Run Code Online (Sandbox Code Playgroud) 背景
我从 API 调用中检索了二进制形式的 pdf:
base_64_binary_data = @response_label[:generate_label_response][:response_shipments][:response_shipment][:labels][:label][:content]
@pdf_file = File.open('label.pdf', 'wb') do |file|
content = Base64.decode64 base_64_binary_data
file << content
end
Run Code Online (Sandbox Code Playgroud)
上面的代码生成了一个我可以查找的文件,它是我需要的清晰图像。
问题
我需要将此图像放在视图中,以便用作发票上的标签。
以下似乎导致了一个很好的解决方案:
@pdf = MiniMagick::Image.new(@pdf_file.path)
@pdf.pages.first.write("preview.png")
Run Code Online (Sandbox Code Playgroud)
它在第二行失败。
MiniMagick::Error
`identify label.pdf` 失败,错误:
...2nd line...
我想工作到这样的功能:
有人可以帮我使用scaphold.io进行第一个查询吗?
当我使用内部GraphiQL查询以下内容时:
query AllPrograms {
viewer {
allPrograms{
edges {
node {
id
name
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
回报看起来像这样:
{
"data": {
"viewer": {
"allPrograms": {
"edges": [
{
"node": {
"id": "UHJvZ3JhbTo2",
"name": "Blender"
}
},
{
"node": {
"id": "UHJvZ3JhbTo1",
"name": "Inkscape"
}
},
...
Run Code Online (Sandbox Code Playgroud)
我的组件看起来像这样:
<template>
<md-card>
<span class="md-headline">Programma's</span>
<span class="md-headline">{{ allPrograms }}</span>
</md-card>
</template>
<script>
import gql from 'graphql-tag'
import config from '../../config/client'
const log = console.log
const allPrograms = gql `
query AllPrograms { …Run Code Online (Sandbox Code Playgroud) arrays ×2
angular ×1
apollo ×1
carrierwave ×1
filter ×1
graphql ×1
javascript ×1
minimagick ×1
pdf ×1
ruby ×1
savon ×1
soap ×1
typescript ×1
vue-apollo ×1
vue.js ×1
xml ×1