小编Jen*_*sen的帖子

Mapbox事件监听器

我已经为MapBox地图添加了自定义按钮,他们正确购物.但是当我添加一个点击监听器时,它不起作用.我在控制台中看到没有错误.

代码如下所示:

const currentLocationControl = new CustomControl('current-location-control', 'GPS');

this.map.addControl(currentLocationControl, 'top-left');

document.getElementById('test').addEventListener('click', function (e) {
    alert('test');
});
Run Code Online (Sandbox Code Playgroud)

我在mounted方法中执行此代码vue.js.

CustomControl:

export default class CustomControl {

    constructor(className, text) {
        this.className = className;
        this.text = text;
    }

    onAdd(map){
        this.map = map;
        this.container = document.createElement('div');
        this.container.id = 'test';
        this.container.className = this.className;
        this.container.textContent = this.text;
        return this.container;
    }
    onRemove(){
        this.container.parentNode.removeChild(this.container);
        this.map = undefined;
    }
}
Run Code Online (Sandbox Code Playgroud)

当我console.log(document.getElementById('test'));在控制台(测试div)中看到预期结果时.

在此输入图像描述

那么可能会发生什么?

javascript mapbox vue.js

14
推荐指数
1
解决办法
425
查看次数

Vue.js交换数组项

在我的vue.js应用程序中,我正在尝试交换2个论坛行,如下所示:

export default {
        data() {
            return {
                forums: []
            }
        },

        methods: {
            increment(forum, index) {
                ForumService.increment(forum)
                    .then(() => {
                        let b = this.forums[index];
                        this.forums[index] = this.forums[index++];
                        this.forums[index++] = b;
                    });
            }
        }
    }
Run Code Online (Sandbox Code Playgroud)

但没有任何反应?我在这做错了什么?

javascript vue.js

7
推荐指数
1
解决办法
2338
查看次数

C#序列化并反序列化json到txt文件

我正在使用NewtonSoft在我的wpf应用程序中处理json.我有一个客户可以保存到txt文件(不涉及数据库).我是这样做的:

public int store(string[] reservation)
{
    JObject customer = new JObject(
        new JProperty("id", this.getNewId()),
        new JProperty("name", reservation[0]),
        new JProperty("address", reservation[1]),
        new JProperty("gender", reservation[2]),
        new JProperty("age", reservation[3])
    );

    using (StreamWriter file = File.CreateText(Settings.databasePath +  "customer.json"))
    using (JsonTextWriter writer = new JsonTextWriter(file))
    {
        customer.WriteTo(writer);
    }

    return 1;
}
Run Code Online (Sandbox Code Playgroud)

结果如下:

{"id":1,"name":"Lars","address":"Bosch 10","gender":"Man","age":"19"}
Run Code Online (Sandbox Code Playgroud)

然后我想让所有客户都这样:

if(File.Exists(Settings.databasePath + "customer.json"))
{
    List<Customer> customers;

    using (StreamReader r = new StreamReader(Settings.databasePath + "customer.json"))
    {
        string json = r.ReadToEnd();
        customers = JsonConvert.DeserializeObject<List<Customer>>(json);
    }
}
Run Code Online (Sandbox Code Playgroud)

但我收到此错误(无法复制错误):

在此输入图像描述已经尝试将其存储为jArray,但这不起作用.我如何让它工作?

任何帮助将不胜感激.:)

c# wpf json list json.net

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

Axios请求拦截器无法正常工作

我正在尝试让axios使用请求拦截器.但是,在发出请求之前,不会触发拦截器.这可能会出错?我已经很多关于这个问题的红色但到目前为止还没有找到解决方案.可以在这里使用一些帮助!这是我的代码:

import VueRouter from 'vue-router';
import Login from './components/Login.vue'
import Home from './components/Home.vue'
import axios from 'axios';

window.Vue = require('vue');

window.axios = axios.create({
    baseURL: 'http://localhost:8080',
    timeout: 10000,
    params: {} // do not remove this, its added to add params later in the config
});


Vue.use(VueRouter);

// Check the user's auth status when the app starts
// auth.checkAuth()


const routes = [
    { path: '/', component: Login, name: 'login' },
    { path: '/home', component: Home, name: 'home', beforeEnter: requireAuth },
]; …
Run Code Online (Sandbox Code Playgroud)

interceptor vue.js axios

6
推荐指数
1
解决办法
7987
查看次数

MapBox超集群错误的集群位置

我正在使用mapbox supercluster制作聚簇地图。我面临的问题是群集不在正确的位置。例如,我只养狗,the netherlands但缩小时它们在法国。

在此处输入图片说明

当我进一步放大时,星团缓慢地移动到荷兰。当我滚动时,簇在地图上移动。

在我的网站https://v2.sayhi.dog/?dog-map=true上可以看到问题。

我的代码如下所示(我使用vue.js):

<template>
    <div class="w-full h-full" id="map"></div>
</template>

<script>
    import mapboxgl from 'mapbox-gl'
    import Supercluster from 'supercluster';

    export default {
        props: ['locations'],

        data() {
            return {
                map: null,
                copyLocations: this.locations,
                clusters: [],
                markers: [],
                clustersGeojson: {},
                clusterIndex: null,
            }
        },

        mounted() {
            mapboxgl.accessToken = 'my-token';
            // init the map
            this.map = new mapboxgl.Map({
                container: 'map',
                style: 'mapbox://styles/sayhi/cjkp9e59x3m3y2rm1zbcc0c',
                zoom: 2,
            });

            this.addControls();
            this.map.on("load", () => { this.addMarkers() });
            this.map.addControl(new …
Run Code Online (Sandbox Code Playgroud)

hierarchical-clustering mapbox vue.js mapbox-gl mapbox-marker

6
推荐指数
1
解决办法
186
查看次数

Vue.js 在组件外设置数据

我有一个组件,我想在组件外设置一个数据项。

我将如何使用指令做到这一点?

我在想这样的事情:

Vue.directive('init', {
    bind: function(el, binding, vnode) {
        vnode.context[binding.arg] = binding.value;
    }
});
Run Code Online (Sandbox Code Playgroud)

但它不起作用:

Vue.directive('init', {
    bind: function(el, binding, vnode) {
        vnode.context[binding.arg] = binding.value;
    }
});
Run Code Online (Sandbox Code Playgroud)
Vue.directive('init', {
  bind: function(el, binding, vnode) {
    vnode.context[binding.arg] = binding.value;
  }
});

Vue.component('test', {
	template: '<p>{{date}}</p>',
  data() {
  	return {
    		date: ""
    }
  }
});

new Vue({
  el: '#app'
})
Run Code Online (Sandbox Code Playgroud)

知道我如何让它发挥作用吗?

- 编辑 -

我不想为此使用道具!我有很多很多领域。

javascript vue.js

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

Vue.js gives weird object with Observer data

我正在使用axios接收数据,如下所示:

getData() {                                        
    Axios.get(                                        
        '/vue/get-data/',                           
        {                                             
            params: {                                 
                categories: this.category,            
                activeFilters: this.activeFilters,    
            }                                         
        }                                             
    ).then((response) => {                            
        this.banners = response.data;                 
        this.setBanner();                             
    })                                                
},           
Run Code Online (Sandbox Code Playgroud)

然后我得到这个:

在此处输入图片说明

当我尝试console.log(response.data.length),我得到undefined。这里发生的事情很奇怪!

当我看vue-devtools横幅时,有2个对象:

在此处输入图片说明

那么如何无法response.data.length定义呢?

javascript vue.js

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

Laravel 高阶消息意外结果

我在 Laravel 中有一个更高阶的消息。它看起来像这样:

$category->scores->each->ratings->where('result.rating', '>=', 3)->count();
Run Code Online (Sandbox Code Playgroud)

Acategoryscores一个scorehasratings和 arating有一个result

我想获得每个类别 的评分总数where >= 3

使用我现在拥有的代码,最终结果始终为 0。

但是当我像这样循环时:

@foreach($categories as $category)
    @foreach($category->scores as $score)
        @foreach($score->ratings->where('result.rating', '>=', 3) as $rating)
            {{ $rating->result->result_nl }}
        @endforeach
    @endforeach
@endforeach
Run Code Online (Sandbox Code Playgroud)

有3个评分结果。

我的高阶消息有什么问题?

php laravel laravel-collection laravel-6

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

Laravel 在其他表中查找平均结果

我在 Laravel 中有这个查询:

DB::table('score')
    ->select('score.score_nl', DB::raw('count(*) as total'), DB::raw('round(avg(rating_results.rating)) as final_rating'))
    ->join('rating', 'rating.score_id', '=', 'score.id')
    ->join('rating_results', 'rating.rating_result_id', '=', 'rating_results.id')
    ->groupBy('score_nl')
    ->get();
Run Code Online (Sandbox Code Playgroud)

结果:

[{"score_nl":"emphatisch","total":1,"final_rating":"1"},{"score_nl":"huilen","total":2,"final_rating":"3"},{"score_nl":"knuffelig","total":1,"final_rating":"1"},{"score_nl":"zindelijkheid","total":2,"final_rating":"3"}]
Run Code Online (Sandbox Code Playgroud)

rating_results在这个表中有一个名为(见图片)的表,我想查找final_rating并获取相关的result_en.

在此处输入图片说明

我怎么能在 Laravel 中做到这一点?

有任何问题请告诉我!

- 编辑 -

我试过这个;

$q = Result::select('result_nl')
    ->whereColumn('rating_results.rating', 'final_rating')
    ->whereColumn('rating_results.score_id', 'score_id')
    ->getQuery();

DB::table('score')
    ->select('score.score_nl', DB::raw('count(*) as total'), DB::raw('round(avg(rating_results.rating)) as final_rating'))
    ->join('rating', 'rating.score_id', '=', 'score.id')
    ->join('rating_results', 'rating.rating_result_id', '=', 'rating_results.id')
    ->selectSub($q, 'result_nl')
    ->groupBy('score_nl')
    ->get();
Run Code Online (Sandbox Code Playgroud)

但是后来我收到了这个错误:

SQLSTATE[42S22]: Column not found: 1247 Reference 'final_rating' not supported (reference to group function) …
Run Code Online (Sandbox Code Playgroud)

mysql sql laravel laravel-query-builder

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

Laravel检查日期是否在2个日期之间.

我想检查今天的日期是否存在于数据库中的日期之间.现在我用laravel雄辩的方式做到这一点:

 return Set::where('type', $type)
            ->where('active_from', '<=', date("Y-m-d"))
            ->where('active_until', '>=', date("Y-m-d"))
            ->first();
Run Code Online (Sandbox Code Playgroud)

它是否正确?

php datetime laravel

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