小编Mar*_*sen的帖子

Lodash _.filter函数必须只满足一个条件

我目前正在使用Lodash _.filter()函数来过滤符合特定条件的对象,这些对象可以是用户搜索,可以是街道地址,城镇或国家.

我已经提取了搜索字符串,并希望针对每个对象中的多个值对其进行过滤,并且如果在任何这些键中找到该字符串,则必须返回该对象.

要解释我想使用网站上的例子.

var users = [
  { 'user': 'barney',  'age': 36, 'active': true },
  { 'user': 'fred',    'age': 40, 'active': false },
  { 'user': 'pebbles', 'age': 1,  'active': true }
];

// using the `_.matches` callback shorthand
_.result(_.find(users, { 'age': 1, 'active': true }), 'user');
Run Code Online (Sandbox Code Playgroud)

在此示例中,我将如何过滤36岁或活跃的用户?

根据文档,似乎需要满足这两个条件,如上面的示例所示,要返回的对象.

javascript arrays object angularjs lodash

18
推荐指数
1
解决办法
4万
查看次数

Laravel Eloquent 查找日期在 JSON 列范围内的所有记录

我正在尝试使用 Eloquent 来查询数据库中的记录表,并且只检索那些由对象数组组成的 json 列中至少有 1 条记录在给定日期范围内的记录。

日期列如下所示:

[
  {'date': '2021-01-01'},
  {'date': '2021-01-02'},
  {'date': '2021-01-03'},
]
Run Code Online (Sandbox Code Playgroud)

如果我通过了“2021-01-01”的开始日期,则需要获取所有日期的记录。*.date 等于或晚于该开始日期。

这同样适用于 end_date。

我有不同类型的语法,例如:

$this->where('dates->[*]->date', '<=', date($value));
$this->where('dates->*->date', '<=', date($value));
$this->where('dates.*.date', '<=', date($value));
Run Code Online (Sandbox Code Playgroud)

似乎没有任何效果。

我究竟做错了什么?

php mysql json laravel eloquent

11
推荐指数
1
解决办法
606
查看次数

Laravel:找不到特质'Illuminate \ Foundation \ Auth \ AuthenticatesAndRegistersUsers'

我正在更新到Laravel 5.4,并在尝试显示登录屏幕时收到以下错误消息。

我收到以下错误消息:

找不到特征'Illuminate \ Foundation \ Auth \ AuthenticatesAndRegistersUsers'

这是AuthController类:

<?php

namespace App\Http\Controllers\Auth;

use App\User;
use Validator;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\ThrottlesLogins;
use Illuminate\Foundation\Auth\AuthenticatesAndRegistersUsers;

class AuthController extends Controller
{
    /*
    |--------------------------------------------------------------------------
    | Registration & Login Controller
    |--------------------------------------------------------------------------
    |
    | This controller handles the registration of new users, as well as the
    | authentication of existing users. By default, this controller uses
    | a simple trait to add these behaviors. Why don't you explore it?
    |
    */

use AuthenticatesAndRegistersUsers, ThrottlesLogins;

/** …
Run Code Online (Sandbox Code Playgroud)

php laravel composer-php

7
推荐指数
2
解决办法
6889
查看次数

从 PHP 中的货币字符串获取数值

我正在尝试从字符串中提取数值,因为我需要在计算总数时使用它。

我在其他线程中读到我应该使用 PHP NumberFormatter函数。

这是我的代码...

PHP

$fmt = new NumberFormatter( 'za_ZA', NumberFormatter::CURRENCY );
$num = "R1,500.00 ZAR";
var_dump($fmt->parseCurrency($num, $curr));
Run Code Online (Sandbox Code Playgroud)

...以及我得到的相应输出。

HTML

<pre class="xdebug-var-dump" dir="ltr"><small>boolean</small> <font color="#75507b">false</font>
</pre>
Run Code Online (Sandbox Code Playgroud)

我也尝试过正则表达式,但它最终给了我 1 而不是 1500。

我不确定错误在哪里以及我应该使用哪种方法。

html php regex currency

5
推荐指数
1
解决办法
4190
查看次数

Laravel:尚未应用特征方法防护,因为与App \ Http \ Controllers \ Auth \ AuthController上的其他特征方法发生冲突

我正在更新到Laravel 5.4,并收到以下错误消息:

尚未应用特性方法防护,因为与App \ Http \ Controllers \ Auth \ AuthController上的其他特征方法存在冲突

这是我的AuthController类。

<?php

namespace App\Http\Controllers\Auth;

use App\User;
use Validator;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\ThrottlesLogins;
use Illuminate\Foundation\Auth\RegistersUsers;
use Illuminate\Foundation\Auth\AuthenticatesUsers;

class AuthController extends Controller
{
    /*
    |--------------------------------------------------------------------------
    | Registration & Login Controller
    |--------------------------------------------------------------------------
    |
    | This controller handles the registration of new users, as well as the
    | authentication of existing users. By default, this controller uses
    | a simple trait to add these behaviors. Why don't you explore it?
    |
    */

use …
Run Code Online (Sandbox Code Playgroud)

php laravel composer-php laravel-5.4

5
推荐指数
1
解决办法
4706
查看次数

在WooCommerce 3中以编程方式设置产品销售价格

我在Woocommerce商店中开设了各种产品类别。

我想对所有属于杜鹃产品类别的产品都享受20%的折扣

目前,我要实现的全部目标是在我的functions.php中设置销售价格

它尝试如下:

    /* 
     * For a specific date, 20% off all products with product category as cuckoo clock.
     */
    function cuckoo_minus_twenty($sale_price, $product) { 
        $sale_price = $product->get_price() * 0.8;
        return $sale_price;
    }; 

    // add the action 
    add_filter( 'woocommerce_get_sale_price', 'cuckoo_minus_twenty', 10, 2 ); 
Run Code Online (Sandbox Code Playgroud)

如果在计算后将var_dump的结果转储为$ sale_price的结果,则会得到正确的答案,但是前端的价格显示会剔除正常价格,并将销售价格显示为正常价格。

在此处输入图片说明

我可以使用钩子/过滤器来实现此目的吗?

我还尝试通过以下方式设置销售价格:

$product->set_sale_price($sale_price); 
Run Code Online (Sandbox Code Playgroud)

无济于事。

php wordpress product woocommerce price

5
推荐指数
1
解决办法
6951
查看次数

Woocommerce订单API订单项ID在更新时更改

我正在通过"订单更新"webhook检索Woocommerce订单,并将特定数据存储在单独的数据库中.

我们还使用个性化插件,允许客户向产品添加自定义消息.这会创建2个单独的行项目,否则后端的产品变体将相同.

在我的单独数据库中,在创建或更新行时,我需要使用order_id,variation_id以及id条目(来自line_items => id)来检查是否必须创建或更新记录.这样可以确保2个相同的产品变体与单独的自定义消息不会相互覆盖.

在订单创建时,将发送以下JSON响应.

{"id":10656,"parent_id":0,"number":"10656","order_key":"wc_order_5a9815fa1add6","created_via":"checkout","version":"3.1.2","status":"pending","currency":"ZAR","date_created":"2018-03-01T17:02:18","date_created_gmt":"2018-03-01T15:02:18","date_modified":"2018-03-01T17:02:18","date_modified_gmt":"2018-03-01T15:02:18","discount_total":"0.00","discount_tax":"0.00","shipping_total":"0.00","shipping_tax":"0.00","cart_tax":"60.79","total":"495.00","total_tax":"60.79","prices_include_tax":true,"customer_id":5148,"customer_ip_address":"197.89.123.74","customer_user_agent":"mozilla\/5.0 (linux; android 6.0.1; samsung sm-g900h build\/mmb29k) applewebkit\/537.36 (khtml, like gecko) samsungbrowser\/6.4 chrome\/56.0.2924.87 mobile safari\/537.36","customer_note":"","billing":{"first_name":"Tasneem","last_name":"Modack","company":"","address_1":"","address_2":"","city":"","state":"","postcode":"","country":"ZA","email":"modackt@webmail.co.za","phone":"0828736647"},"shipping":{"first_name":"Tasneem","last_name":"Modack","company":"","address_1":"","address_2":"","city":"","state":"","postcode":"","country":"ZA"},"payment_method":"payfast","payment_method_title":"Pay With Your Card or Instant EFT.","transaction_id":"","date_paid":null,"date_paid_gmt":null,"date_completed":null,"date_completed_gmt":null,"cart_hash":"666062e6d9100aa43860fb71caef1466","meta_data":[{"id":506232,"key":"_store_location","value":"loop-street-cbd"},{"id":506233,"key":"_collection_date","value":"3 March, 2018"},{"id":506234,"key":"_collection_time","value":"10:00 AM"},{"id":506235,"key":"mailchimp_woocommerce_is_subscribed","value":"1"},{"id":506259,"key":"_billing_vat_number","value":""}],"line_items":[{"id":28607,"name":"Rainbow - Yes (add R50.00)","product_id":415,"variation_id":2590,"quantity":1,"tax_class":"","subtotal":"434.21","subtotal_tax":"60.79","total":"434.21","total_tax":"60.79","taxes":[{"id":1,"total":"60.79","subtotal":"60.79"}],"meta_data":[{"id":194971,"key":"transform-into-a-pinata","value":"Yes (add R50.00)"}],"sku":"N005-P","price":434.21,"_product_group":"rainbow-cakes"}],"tax_lines":[{"id":28609,"rate_code":"ZA-VAT-1","rate_id":1,"label":"VAT","compound":false,"tax_total":"60.79","shipping_tax_total":"0.00","meta_data":[]}],"shipping_lines":[{"id":28608,"method_title":"Local pickup","method_id":"local_pickup:10","total":"0.00","total_tax":"0.00","taxes":[],"meta_data":[{"id":194976,"key":"Items","value":"Rainbow - Yes (add R50.00) × 1"}]}],"fee_lines":[],"coupon_lines":[],"refunds":[]}
Run Code Online (Sandbox Code Playgroud)

创建订单时,line_item => id为28607

在订单更新时,将发送以下JSON响应.

{"id":10656,"parent_id":0,"number":"10656","order_key":"wc_order_5a9815fa1add6","created_via":"checkout","version":"3.1.2","status":"pending","currency":"ZAR","date_created":"2018-03-01T17:02:18","date_created_gmt":"2018-03-01T15:02:18","date_modified":"2018-03-01T17:02:18","date_modified_gmt":"2018-03-01T15:02:18","discount_total":"0.00","discount_tax":"0.00","shipping_total":"0.00","shipping_tax":"0.00","cart_tax":"60.79","total":"495.00","total_tax":"60.79","prices_include_tax":true,"customer_id":5148,"customer_ip_address":"197.89.123.74","customer_user_agent":"mozilla\/5.0 (linux; android 6.0.1; samsung sm-g900h build\/mmb29k) applewebkit\/537.36 (khtml, like gecko) samsungbrowser\/6.4 chrome\/56.0.2924.87 mobile safari\/537.36","customer_note":"","billing":{"first_name":"Tasneem","last_name":"Modack","company":"","address_1":"","address_2":"","city":"","state":"","postcode":"","country":"ZA","email":"modackt@webmail.co.za","phone":"0828736647"},"shipping":{"first_name":"Tasneem","last_name":"Modack","company":"","address_1":"","address_2":"","city":"","state":"","postcode":"","country":"ZA"},"payment_method":"payfast","payment_method_title":"Pay With Your Card or Instant EFT.","transaction_id":"","date_paid":null,"date_paid_gmt":null,"date_completed":null,"date_completed_gmt":null,"cart_hash":"666062e6d9100aa43860fb71caef1466","meta_data":[{"id":506232,"key":"_store_location","value":"loop-street-cbd"},{"id":506233,"key":"_collection_date","value":"3 March, 2018"},{"id":506234,"key":"_collection_time","value":"1:00 PM"},{"id":506235,"key":"mailchimp_woocommerce_is_subscribed","value":"1"},{"id":506256,"key":"_billing_vat_number","value":""}],"line_items":[{"id":28604,"name":"Rainbow - Yes …
Run Code Online (Sandbox Code Playgroud)

php wordpress json woocommerce woocommerce-rest-api

5
推荐指数
1
解决办法
567
查看次数

Vue.js 向父组件发送对象

我无法弄清楚为什么我无法在父组件中监听子组件的更改。

我有一个自定义<v-address></v-address>组件,其中包含多个输入字段,供用户输入地址,如下所示:

<v-text-field
  v-model="address.address_line_1"
  label="Street Address"
  required
  @change="inputChanged">
</v-text-field>
Run Code Online (Sandbox Code Playgroud)

在下面我聆听变化:

import { mapGetters, mapActions } from 'vuex';
    export default {
        data() {
            return {
                address: {
                    address_line_1: '',
                    address_line_2: '',
                    city: '',
                    province: '',
                    postal_code: ''
                }
            }
        },
        computed: {
            ...mapGetters([
                'getProvinces',
            ]),
        },
        methods: {
            inputChanged() {
                this.$emit('address:change', this.address);
            }
        }
    }
Run Code Online (Sandbox Code Playgroud)

每次更改输入字段时,我都想将整个地址对象发送到父组件。

当我console.log(this.address)进入该inputChanged()方法时,我得到了包含所有可用值的正确对象。

我现在想像这样发出对象: this.$emit('address:change', this.address);

使用 vue devtools 我得到了正确的发射: 在此输入图像描述

在我的父组件中,我监听<v-address @address:change="changeAddress"></v-address>组件中的更改。

然后,在我的父组件中,我尝试输出这些更改:

methods: {
   ...mapActions([
       'setE6',
   ]),
   changeAddress(value, …
Run Code Online (Sandbox Code Playgroud)

javascript components emit vue.js

5
推荐指数
1
解决办法
1万
查看次数

FormInput 组件下的 React Native Elements Line

我正在使用 React Native Elements 中的 FormInput 元素,它似乎在每个 FormInput 组件下方生成一行。一个比另一个更微弱。

在此处输入图片说明

表格如下

<View style={styles.container}>
                <Image 
                    style={styles.image}
                    source={app.imageBackground}
                />
                <View style={{ alignItems: 'center' }}>
                    <Image 
                        style={styles.logo}
                        source={app.logo}
                    />
                </View>

                <View  style={styles.cardWrapper}>
                    <View style={styles.card}>
                        <FormInput 
                            inputStyle={styles.textInput}
                            placeholder='user@email.com'
                            autoCapitalize='none'
                            autoCorrect={false}
                            underlineColorAndroid='transparent'
                            placeholderTextColor='white'
                            onChangeText={this.onEmailChange.bind(this)} 
                        />
                        <FormInput 
                            secureTextEntry={true}
                            autoCapitalize='none'
                            placeholder='password'
                            autoCorrect={false}
                            inputStyle={styles.textInput}
                            underlineColorAndroid='transparent'
                            placeholderTextColor = 'white'
                            onChangeText={this.onPasswordChange.bind(this)} 
                        />
                        <FormValidationMessage>{this.renderError()}</FormValidationMessage>
                        {this.renderButton()}

                        <Text style={{color:'white', textAlign:'center'}}>New to Foodspecials?<Text style={{fontWeight:'900'}} onPress={() => this.props.navigation.navigate('SignUp')}> Sign up</Text></Text>
                    </View>
                </View>

            </View>
Run Code Online (Sandbox Code Playgroud)

这是我的风格

const styles = StyleSheet.create({
    container: {
        flex: 1,
        justifyContent: 'center',
    },
    cardWrapper: …
Run Code Online (Sandbox Code Playgroud)

javascript css reactjs react-native

4
推荐指数
3
解决办法
5022
查看次数

VueTable 2 $ refs对象在已安装的挂钩中为空

我读过几篇文章,其中vue实例的$ refs属性仅在Vue.js的挂接钩中可用

我在vue组件中设置了一个自定义事件侦听器,用于侦听输入字段中日期的变化。一旦发生这种情况,我将更改日期的查询参数以从我的API中获取一组新的结果。

我的问题是我无法使用新的查询参数运行refresh()方法。

这是我的组成部分

<template>
    <vuetable
        :fields="table.fields"
        :apiUrl="table.url"
        :append-params="urlParams"
    ></vuetable>
</template>

<script>
    import { eventBus } from '../app.js';
    import Vuetable from 'vuetable-2';
    import moment from 'moment';

    export default {
        data: function() {
            return {
                urlParams: {
                    d: moment().add(1, 'd')._d, // date selected
                    //p: null, // product selected
                },
                lineItems: '',
                table: {
                    url: '/home/bakery/lineitems/', // by default we need tomorrows orders
                    showTable: false,
                    fields: [
                        { name: 'order_id', title: 'Order#' }, 
                        { name: 'customer_name', title: 'Customer' }, …
Run Code Online (Sandbox Code Playgroud)

javascript hook lifecycle vuejs2

3
推荐指数
1
解决办法
3042
查看次数