糖粟与秋泊

文章 评论 浏览 27

糖粟与秋泊 2025-01-24 09:11:58

includes 在这里不起作用,因为它只会比较严格相等的项目(如 item1 === item2)。仅当您的项目是具有相同引用的相同对象时,它才有效。

一个小例子:

const obj1 = { test: 1 };
const obj2 = obj1;
const obj3 = { test: 1 };

console.log(obj1 === obj2); // true
console.log(obj1 === obj3); // false

因此,在您的情况下,您必须在过滤器函数中执行更复杂的工作:

const availableItems = items.filter(item1 => !purchasedItems.some(item2 => item1.id === item2.id));

includes won't work here because it will only compare the items with a strict equality (as in item1 === item2). It will only works if your items are the same objects with the same reference.

A little example:

const obj1 = { test: 1 };
const obj2 = obj1;
const obj3 = { test: 1 };

console.log(obj1 === obj2); // true
console.log(obj1 === obj3); // false

So, in your case, you have to do a more complex work in your filter function:

const availableItems = items.filter(item1 => !purchasedItems.some(item2 => item1.id === item2.id));

从另一个数组中删除一个数组中出现的元素

糖粟与秋泊 2025-01-24 08:05:29

使用 Object.defineProperties 通过将 X, Y 属性分配给 window 对象来声明变量(如果您希望变量成为全局变量) , 和创建 Y 作为访问器属性(又名getter,基本上是一个计算属性):

Object.defineProperties(window, {
  _X: {
    value: undefined,
    writable: true,
    enumerable: true,
    configurable: true,
  },
  X: {
    set: function(val) {
      const currentVal = Number(val);
      if (isNaN(currentVal) || currentVal < 0 || currentVal > 100) {
        throw(`Failed to assign ${val} to X. It can only be assigned numeric values from 0 to 100`);
      } else {
        this._X = val;
      }
    },
    get: function() { return this._X },
    enumerable: true,
    configurable: true,
  },
  Y: {
    get: function() { return - 90 + this.X * 1.8 },
    enumerable: true,
    configurable: true,
  }
});

X = 100;
console.log(Y); // 90
X = 0;
console.log(Y); // -90
X = 50;
console.log(Y); // 0
try {
  X = 101; // Failed to assign 101 to X. It can only be assigned numeric values from 0 to 100
} catch (e) { console.error(e); }

注意:我还添加了一个安全措施,不允许将无效值分配给 X

Use Object.defineProperties to declare your variables by assigning X, Y properties to the window object, if you want your variables to be global variables, and create Y as an accessor property (a.k.a. getter, basically a computed property):

Object.defineProperties(window, {
  _X: {
    value: undefined,
    writable: true,
    enumerable: true,
    configurable: true,
  },
  X: {
    set: function(val) {
      const currentVal = Number(val);
      if (isNaN(currentVal) || currentVal < 0 || currentVal > 100) {
        throw(`Failed to assign ${val} to X. It can only be assigned numeric values from 0 to 100`);
      } else {
        this._X = val;
      }
    },
    get: function() { return this._X },
    enumerable: true,
    configurable: true,
  },
  Y: {
    get: function() { return - 90 + this.X * 1.8 },
    enumerable: true,
    configurable: true,
  }
});

X = 100;
console.log(Y); // 90
X = 0;
console.log(Y); // -90
X = 50;
console.log(Y); // 0
try {
  X = 101; // Failed to assign 101 to X. It can only be assigned numeric values from 0 to 100
} catch (e) { console.error(e); }

Note: I also added a safeguard that won't allow to assign invalid values to X.

JavaScript-根据其他值增加值

糖粟与秋泊 2025-01-24 05:33:20

通过快速谷歌,我找到了第一个结果:
https://github.com/rrrovalle/tesla-car-app

似乎有可能。试试你的运气,谷歌搜索并查看 pub.dev。
也许有一个包裹。也许你必须自己实现它或者使用平台渠道中的原生包。

或许有解决办法。但你必须自己做一些研究。

With a quick google I was able to find this as the first result:
https://github.com/rrrovalle/tesla-car-app

Seems possible. Just try your luck googling and looking on pub.dev.
Maybe there's a package. Maybe you have to implement it yourself or use native packages in the platform channels.

There's probably a solution. But you will have to do some research yourself.

Flutter App 是否可以解锁和锁定车门?

糖粟与秋泊 2025-01-24 04:48:14

这是一种方法,使用 UNION ALL (请参阅 SQL Fiddle with演示)。这适用于两个组,如果您有两个以上的组,则需要指定编号并为每个添加查询:

(
  select *
  from mytable 
  where `group` = 1
  order by age desc
  LIMIT 2
)
UNION ALL
(
  select *
  from mytable 
  where `group` = 2
  order by age desc
  LIMIT 2
)

有多种方法为此,请参阅本文以确定适合您情况的最佳路线:

http://www.xaprb.com/blog/2006/12/07/how-to-select-the-firstleastmax-row-per-group-in-sql/

编辑:

这可能也适合您,它为每条记录生成一个行号。使用上面链接中的示例,这将仅返回行数小于或等于 2 的记录:

select person, `group`, age
from 
(
   select person, `group`, age,
      (@num:=if(@group = `group`, @num +1, if(@group := `group`, 1, 1))) row_number 
  from test t
  CROSS JOIN (select @num:=0, @group:=null) c
  order by `Group`, Age desc, person
) as x 
where x.row_number <= 2;

请参阅演示

Here is one way to do this, using UNION ALL (See SQL Fiddle with Demo). This works with two groups, if you have more than two groups, then you would need to specify the group number and add queries for each group:

(
  select *
  from mytable 
  where `group` = 1
  order by age desc
  LIMIT 2
)
UNION ALL
(
  select *
  from mytable 
  where `group` = 2
  order by age desc
  LIMIT 2
)

There are a variety of ways to do this, see this article to determine the best route for your situation:

http://www.xaprb.com/blog/2006/12/07/how-to-select-the-firstleastmax-row-per-group-in-sql/

Edit:

This might work for you too, it generates a row number for each record. Using an example from the link above this will return only those records with a row number of less than or equal to 2:

select person, `group`, age
from 
(
   select person, `group`, age,
      (@num:=if(@group = `group`, @num +1, if(@group := `group`, 1, 1))) row_number 
  from test t
  CROSS JOIN (select @num:=0, @group:=null) c
  order by `Group`, Age desc, person
) as x 
where x.row_number <= 2;

See Demo

获取每组分组结果的前n条记录

糖粟与秋泊 2025-01-24 01:52:33

首先设置库搜索路径:

link_directories(${CMAKE_BINARY_DIR}/res)

然后就可以了

target_link_libraries(GLBall mylib)

Set libraries search path first:

link_directories(${CMAKE_BINARY_DIR}/res)

And then just do

target_link_libraries(GLBall mylib)

CMake 链接到外部库

糖粟与秋泊 2025-01-23 22:43:00

您无法更改共享的代码来提高性能。您唯一的选择是获得更快的互联网连接(更低的延迟和/或更多的带宽)。

从屏幕截图来看,阅读该文档似乎需要 53 毫秒,乍一看,这对我来说似乎相当合理。

There's nothing you can change about the code you shared to improve the performance. Your only options would be to get a faster internet connection (lower latency and/or more bandwidth).

From the screenshot it seems to take 53ms to read the document, which seems pretty reasonably to me at first glance.

如何提高 Firebase firestore 查询的性能

糖粟与秋泊 2025-01-23 18:59:29

因为 SomeFunction 实际上有一个名为“this”的不可见参数。

像这样写:

smallClass.function = std::bind(&BigClass::SomeFunction, this);

或者使用 lambda:

smallClass.function = [this]() { SomeFunction(); };

Because SomeFunction acturally has a invisible argument called 'this'.

Write like this:

smallClass.function = std::bind(&BigClass::SomeFunction, this);

or use lambda:

smallClass.function = [this]() { SomeFunction(); };

类中的 std::function 设置为包含第一个类的类中的函数

糖粟与秋泊 2025-01-22 14:28:23

据我从 pyinstaller 网站上看到,他们已经从 4.0 版中删除了对 python2.7 的支持,并且您正在尝试安装 4.1.0 版(https://pyinstaller.readthedocs.io/en/stable/)

最后,此版本放弃了对 Python 2.7 的支持,自 2020 年 1 月起就已停止使用。现在所需的最低版本是 Python 3.6。

另外,我在 PyPI 上没有看到任何其他可用版本,因此您唯一的选择是将 python 升级到至少版本 3.6。

祝你好运!

As far as I can see from the pyinstaller website they have dropped the support of python2.7 from version 4.0, and you are trying to install a version 4.1.0 (https://pyinstaller.readthedocs.io/en/stable/)

Finally, this version drops support for Python 2.7, which is end-of-life since January 2020.. The minimum required version is now Python 3.6.

Also, I do not see any other available version on PyPI, so the only option you have is to upgrade your python to at least version 3.6.

Best of luck!

在 Python 2.7 中安装包时 Pip 返回语法错误

糖粟与秋泊 2025-01-22 10:01:40

使用连接

var Result = (from s in _context.Suppliers
             join t in _context.TypeSuppliers on s.typeId equals t.supplierItemTypdId
             where t.supplierItemTypdId == 1
             select s
             ).ToList();

Use join

var Result = (from s in _context.Suppliers
             join t in _context.TypeSuppliers on s.typeId equals t.supplierItemTypdId
             where t.supplierItemTypdId == 1
             select s
             ).ToList();

如何使用 Linq 从多对多表访问字段或属性?

糖粟与秋泊 2025-01-22 09:48:35

由于您位于 php 标记内,因此您的 echo 输出应该用引号引起来:

<?php
        if (isset($_GET["error"])) {
            if ($_GET["error"] == "emptyinput") {
            }
            else if ($_GET["error"] == "invaliduid") {
                echo "<p>Improper username</p>";
            }
            else if ($_GET["error"] == "invalidemail") {
                echo "<p>Choose a proper email</p>";
            }
            else if ($_GET["error"] == "pwdsdontmatch") {
                echo "<p>Passwords do not match</p>";
            }
            else if ($_GET["error"] == "stmtfailed") {
                echo "<p>Something went wrong. Try again.</p>";
            }
            else if ($_GET["error"] == "uidtaken") {
                echo "<p>Username taken</p>";
            }
            else if ($_GET["error"] == "none") {
                echo "<p>You are all signed up!</p>";
            }
        }
?>

Since you are inside the php tag, your echo output should be encased in quotes:

<?php
        if (isset($_GET["error"])) {
            if ($_GET["error"] == "emptyinput") {
            }
            else if ($_GET["error"] == "invaliduid") {
                echo "<p>Improper username</p>";
            }
            else if ($_GET["error"] == "invalidemail") {
                echo "<p>Choose a proper email</p>";
            }
            else if ($_GET["error"] == "pwdsdontmatch") {
                echo "<p>Passwords do not match</p>";
            }
            else if ($_GET["error"] == "stmtfailed") {
                echo "<p>Something went wrong. Try again.</p>";
            }
            else if ($_GET["error"] == "uidtaken") {
                echo "<p>Username taken</p>";
            }
            else if ($_GET["error"] == "none") {
                echo "<p>You are all signed up!</p>";
            }
        }
?>

有谁知道如何修复 php 中的这个错误?

糖粟与秋泊 2025-01-22 05:19:10

您可以获得车辆路线的所有组合及其行驶时间的数组,并通过寻找更短的时间和更快的车辆来减少这个数组。

const
    vehicles = [{ name: 'TukTuk', maxSpeed: 12 }, { name: 'Bike', maxSpeed: 10 }, { name: 'Car', maxSpeed: 20 }],
    routes = [{ name: 'routeOne' , distance: 18, allowedSpeed: 12 }, {name: 'routeTwo',  distance: 20, allowedSpeed: 10 }],
    getTravelTime = (vehicle, route) => route.distance / (route.allowedSpeed < vehicle.maxSpeed ? route.allowedSpeed : vehicle.maxSpeed),
    result = vehicles
        .flatMap(v => routes.map(r => ({ 
            vehicle: v.name,
            maxSpeed: v.maxSpeed,
            route: r.name,
            time: getTravelTime (v, r)
        })))
        .reduce((a, b) => 
            a.time === b.time && a.maxSpeed > b.maxSpeed ||
            a.time < b.time
                ? a
                : b
        );

console.log(result);
.as-console-wrapper { max-height: 100% !important; top: 0; }

You could get an array of all combinations of vehicles and routes and their travel time and reduce this array by looking for shorter time and faster vehicle.

const
    vehicles = [{ name: 'TukTuk', maxSpeed: 12 }, { name: 'Bike', maxSpeed: 10 }, { name: 'Car', maxSpeed: 20 }],
    routes = [{ name: 'routeOne' , distance: 18, allowedSpeed: 12 }, {name: 'routeTwo',  distance: 20, allowedSpeed: 10 }],
    getTravelTime = (vehicle, route) => route.distance / (route.allowedSpeed < vehicle.maxSpeed ? route.allowedSpeed : vehicle.maxSpeed),
    result = vehicles
        .flatMap(v => routes.map(r => ({ 
            vehicle: v.name,
            maxSpeed: v.maxSpeed,
            route: r.name,
            time: getTravelTime (v, r)
        })))
        .reduce((a, b) => 
            a.time === b.time && a.maxSpeed > b.maxSpeed ||
            a.time < b.time
                ? a
                : b
        );

console.log(result);
.as-console-wrapper { max-height: 100% !important; top: 0; }

Javascript - 在另一种功能方式中循环两个数组

糖粟与秋泊 2025-01-22 01:56:09

您可以使用 for 循环和条件来绘制圆圈,在每次迭代中递增 x 和 y 值。

let pos1 = {x:383,y:202};
let pos2 = {x:754,y:387};

let dotRadius = 5;

let divisions = 10;

// Try to create 'divisions' amount of dots between pos1 and pos2

let increment_x = (pos2.x-pos1.x)/(divisions+1)
let increment_y = (pos2.y-pos1.y)/(divisions+1)


function setup() {
  createCanvas(768,768);
  
}

function draw() {
  background(50,50,50);
  rectMode(CENTER);
  
  stroke(180,180,180);
  
  circle(pos1.x, pos1.y,dotRadius);
  circle(pos2.x, pos2.y,dotRadius);

  let y=pos1.y
  
  for (let x=pos1.x; x<pos2.x; x+=increment_x) {
    if (y<pos2.y){
      circle(x, y,dotRadius);
    }
    y+=increment_y
  }
}

You can use a for loop and conditionals to draw the circles incrementing the x and y values in each iteration.

let pos1 = {x:383,y:202};
let pos2 = {x:754,y:387};

let dotRadius = 5;

let divisions = 10;

// Try to create 'divisions' amount of dots between pos1 and pos2

let increment_x = (pos2.x-pos1.x)/(divisions+1)
let increment_y = (pos2.y-pos1.y)/(divisions+1)


function setup() {
  createCanvas(768,768);
  
}

function draw() {
  background(50,50,50);
  rectMode(CENTER);
  
  stroke(180,180,180);
  
  circle(pos1.x, pos1.y,dotRadius);
  circle(pos2.x, pos2.y,dotRadius);

  let y=pos1.y
  
  for (let x=pos1.x; x<pos2.x; x+=increment_x) {
    if (y<pos2.y){
      circle(x, y,dotRadius);
    }
    y+=increment_y
  }
}

如何在 P5.js 画布上的 2 个位置之间创建点?

糖粟与秋泊 2025-01-21 05:43:03

我通过将 viewModelScope 传递给我的 UseCase(上面的 getPagerObservable)并将其缓存在那里来修复它,如下所示:

//GetPagerObservable UseCase

operator fun invoke(scope: CoroutineScope): Observable<PagingData<Item>> {
        return repository.getObservable()
            .cachedIn(scope)
            .map { data ->
                data.filter { it.isNotEmpty() }
            }
    }

I fixed it by passing viewModelScope to my UseCase (getPagerObservable above) and caching it there like so:

//GetPagerObservable UseCase

operator fun invoke(scope: CoroutineScope): Observable<PagingData<Item>> {
        return repository.getObservable()
            .cachedIn(scope)
            .map { data ->
                data.filter { it.isNotEmpty() }
            }
    }

Android 分页库 3 - 出现错误“尝试从 pageEventFlow 收集两次...”当导航回片段时

糖粟与秋泊 2025-01-20 19:06:18

对于问题 1

在这里,您可以在 $query->has('products', '>', 0) 上放置一个条件,但似乎您正在使用构建器插件,因此您只需放置一个类别产品数量的条件。

{% for category in categories %}
  {% if category.products|length > 0 %}
    {{category.name}}. // here you will get only category which has products.
  {% endif %}
{% endfor %}

对于问题 2,

如果有任何疑问,您可以这样做,

{% if record.options|length > 0 %}
  show them
{% else %}
  no options
{% endif %}

请发表评论。

For Question number 1

Here you can put a condition on $query->has('products', '>', 0) but seems you are using the builder plugin so you can simply put a condition on the category product count.

{% for category in categories %}
  {% if category.products|length > 0 %}
    {{category.name}}. // here you will get only category which has products.
  {% endif %}
{% endfor %}

For Question number 2

You can do something like this

{% if record.options|length > 0 %}
  show them
{% else %}
  no options
{% endif %}

if any doubt please comment.

如何删除空类别?

糖粟与秋泊 2025-01-20 17:53:05

使用 eBay API getOrders,无需任何 sdk

即使不将 DetailLevel 设置为 ReturnAll,它也会正确返回 SellerUserID

using eBay API getOrders, without any sdk

it returns correctly the SellerUserID even without setting DetailLevel to ReturnAll

API响应不返回OrderArray.Order.SellerUserID

更多

推荐作者

櫻之舞

文章 0 评论 0

弥枳

文章 0 评论 0

m2429

文章 0 评论 0

野却迷人

文章 0 评论 0

我怀念的。

文章 0 评论 0

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文