使用 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
。
通过快速谷歌,我找到了第一个结果:
https://github.com/rrrovalle/tesla-car-app
似乎有可能。试试你的运气,谷歌搜索并查看 pub.dev。
也许有一个包裹。也许你必须自己实现它或者使用平台渠道中的原生包。
或许有解决办法。但你必须自己做一些研究。
这是一种方法,使用 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;
请参阅演示
首先设置库搜索路径:
link_directories(${CMAKE_BINARY_DIR}/res)
然后就可以了
target_link_libraries(GLBall mylib)
您无法更改共享的代码来提高性能。您唯一的选择是获得更快的互联网连接(更低的延迟和/或更多的带宽)。
从屏幕截图来看,阅读该文档似乎需要 53 毫秒,乍一看,这对我来说似乎相当合理。
因为 SomeFunction
实际上有一个名为“this”的不可见参数。
像这样写:
smallClass.function = std::bind(&BigClass::SomeFunction, this);
或者使用 lambda:
smallClass.function = [this]() { SomeFunction(); };
据我从 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。
祝你好运!
使用连接
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();
由于您位于 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>";
}
}
?>
您可以获得车辆
和路线
的所有组合及其行驶时间的数组,并通过寻找更短的时间和更快的车辆来减少这个数组。
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; }
您可以使用 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
}
}
我通过将 viewModelScope 传递给我的 UseCase(上面的 getPagerObservable)并将其缓存在那里来修复它,如下所示:
//GetPagerObservable UseCase
operator fun invoke(scope: CoroutineScope): Observable<PagingData<Item>> {
return repository.getObservable()
.cachedIn(scope)
.map { data ->
data.filter { it.isNotEmpty() }
}
}
对于问题 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 %}
请发表评论。
使用 eBay API getOrders
,无需任何 sdk
,
即使不将 DetailLevel
设置为 ReturnAll,它也会正确返回
SellerUserID
includes
在这里不起作用,因为它只会比较严格相等的项目(如item1 === item2
)。仅当您的项目是具有相同引用的相同对象时,它才有效。一个小例子:
因此,在您的情况下,您必须在过滤器函数中执行更复杂的工作:
includes
won't work here because it will only compare the items with a strict equality (as initem1 === item2
). It will only works if your items are the same objects with the same reference.A little example:
So, in your case, you have to do a more complex work in your filter function:
从另一个数组中删除一个数组中出现的元素