有没有开发使用setAttribute而不是dot(.)属性表示法的最佳实践?
例如:
myObj.setAttribute("className", "nameOfClass");
myObj.setAttribute("id", "someID");
Run Code Online (Sandbox Code Playgroud)
要么
myObj.className = "nameOfClass";
myObj.id = "someID";
Run Code Online (Sandbox Code Playgroud) 我正在开发一个基于iPad的网络应用程序,需要防止过度滚动,以免它看起来像网页.我目前正在使用它来冻结视口并禁用过度滚动:
document.body.addEventListener('touchmove',function(e){
e.preventDefault();
});
Run Code Online (Sandbox Code Playgroud)
这可以很好地禁用过度滚动,但我的应用程序有几个可滚动的div,上面的代码阻止它们滚动.
我只针对iOS 5及以上版本,所以我避免使用像iScroll这样的hacky解决方案.相反,我将这个CSS用于我的可滚动div:
.scrollable {
-webkit-overflow-scrolling: touch;
overflow-y:auto;
}
Run Code Online (Sandbox Code Playgroud)
这没有文档overscroll脚本,但不解决div滚动问题.
没有jQuery插件,有没有办法使用过度滚动修复但免除我的$('.scrollable')divs?
编辑:
我发现了一些不错的解决方案:
// Disable overscroll / viewport moving on everything but scrollable divs
$('body').on('touchmove', function (e) {
if (!$('.scrollable').has($(e.target)).length) e.preventDefault();
});
Run Code Online (Sandbox Code Playgroud)
滚动浏览div的开头或结尾时,视口仍会移动.我想找到一种方法来禁用它.
在numpy中,为什么减去整数有时会产生浮点数?
>>> x = np.int64(2) - np.uint64(1)
>>> x
1.0
>>> x.dtype
dtype('float64')
Run Code Online (Sandbox Code Playgroud)
这似乎只发生在使用多个不同的整数类型(例如有符号和无符号)时,以及没有更大的整数类型可用时.
我一直在编写一个可以通过 pip 安装的新 Django 包。我被困了一段时间,因为我不确定如何为我的特定包进行迁移,以便允许安装的正常工作流程是:
python manage.py migrate目前,我的包裹是这样的:
package_root/
dist/
actual_package/
__init__.py
models.py
setup.py
Run Code Online (Sandbox Code Playgroud)
我面临的问题是,当我打包应用程序并使用安装它pip install dist/...然后将它添加到我的示例应用程序“INSTALLED_APPS”时,运行python manage.py migrate不会为模型创建任何表actual_package/models.py,因此我(从用户的角度)需要然后python manage.py makemigrations actual_package首先运行,这并不理想。
关于如何在用户安装之前对迁移进行排序的任何想法都非常好。
我一直在尝试追踪一些并发代码中的一些错误,并想编写一个并行运行函数的测试。我使用 Django 和 postgres 作为我的数据库,并使用 pytest 和 pytest-django 进行测试。
为了运行我的函数,我使用ThreadPoolExecutor并简单地查询我的数据库并返回对象计数。这是 django shell 中的测试按预期工作:
>>> from concurrent.futures import *
>>> def count_accounts():
... return Account.objects.all().count()
...
>>> count_accounts()
2
>>> with ThreadPoolExecutor(max_workers=1) as e:
... future = e.submit(count_accounts)
...
>>> for f in as_completed([future]):
... print(f.result())
...
2
Run Code Online (Sandbox Code Playgroud)
但是,当我在 pytest 下运行此测试时,线程中的函数似乎返回空查询集:
class TestCountAccounts(TestCase):
def test_count_accounts(self):
def count_accounts():
return Account.objects.all().count()
initial_result = count_accounts() # 2
with ThreadPoolExecutor(max_workers=1) as e:
future = e.submit(count_accounts)
for f in as_completed([future]):
assert f.result() == initial_result …Run Code Online (Sandbox Code Playgroud) 我有一个在 Nginx 代理后面运行的 Django REST Framework 应用程序,我们有一个第三方服务,可以重定向到应用程序中的一个 url。当重定向发生时,我从这个端点收到 502s,并将其缩小到 Referer 标头太大。我的逻辑如下:
我试过增加我的 uwsgi 缓冲区大小和 nginx 代理缓冲区。
我最近开始使用Jenkins,我想使用Multibranch Pipelines,所以我可以在我的项目中测试各种功能分支.
该项目正在使用django 1.8.到目前为止,我的Jenkinsfile看起来像这样并且在测试阶段失败,因为django无法找到我的设置文件,即使它在那里:
node {
// Mark the code checkout 'stage'....
stage 'Checkout'
// Get the code from a GitHub repository
git credentialsId: 'mycredentials', url: 'https://github.com/<user>/<project>/'
// Mark the code build 'stage'....
stage 'Build'
env.WORKSPACE = pwd()
sh 'virtualenv --python=python34 venv'
sh 'source venv/bin/activate'
sh 'pip install -r requirements.txt'
env.DJANGO_SETTINGS_MODULE = "<appname>.settings.jenkins"
// Start the tests
stage 'Test'
sh 'python34 manage.py test --keepdb'
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试实现一个可水平滚动(使用React)的表,在每一行中都有一个下拉组件。该组件是自定义的,不使用<select>标记。我注意到在表格的底部,当我打开输入时,由于表格具有,所以选项被隐藏了overflow-x: scroll。如果我使用<select>标签,这不是问题,但是我需要重建自定义下拉列表及其所有功能。此处提供了一个演示:https : //codesandbox.io/embed/frosty-moon-pz0y3
您会注意到,除非您在表格中滚动,否则第一列不会显示选项,第二列会根据需要显示选项。我的问题是如何在维护overflow-x: scroll整个表的同时允许第一列溢出。
代码如下:
import React from "react";
import ReactDOM from "react-dom";
import Select from "react-select";
import "./styles.css";
function App() {
const options = [
{
value: "Volvo", label: "Volvo"
},
{
value: "Saab", label: "Saab"
},
{
value: "Merc", label: "Merc"
},
{
value: "BMW", label: "BMW"
}
];
return (
<div className="App">
<div className="table-wrapper">
<table>
<thead>
<th>Col1</th>
<th>Col2</th>
<th>Col3</th>
</thead>
<tbody>
<tr>
<td>
<Select options={options} value="Volvo" …Run Code Online (Sandbox Code Playgroud) 我有一张图片:
newGameButton = pygame.image.load("images/newGameButton.png").convert_alpha()
Run Code Online (Sandbox Code Playgroud)
然后我在屏幕上显示它:
screen.blit(newGameButton, (0,0))
Run Code Online (Sandbox Code Playgroud)
如何检测鼠标是否正在触摸图像?
我正在学习python中的描述符.我想编写一个非数据描述符,但是__get__当我调用classmethod时,具有描述符作为其类方法的类不会调用特殊方法.这是我的例子(没有__set__):
class D(object):
"The Descriptor"
def __init__(self, x = 1395):
self.x = x
def __get__(self, instance, owner):
print "getting", self.x
return self.x
class C(object):
d = D()
def __init__(self, d):
self.d = d
Run Code Online (Sandbox Code Playgroud)
以下是我称之为:
>>> c = C(4)
>>> c.d
4
Run Code Online (Sandbox Code Playgroud)
该__get__描述符类的就没有得到调用.但是当我也设置一个__set__描述符似乎被激活:
class D(object):
"The Descriptor"
def __init__(self, x = 1395):
self.x = x
def __get__(self, instance, owner):
print "getting", self.x
return self.x
def __set__(self, instance, value):
print "setting", self.x
self.x = …Run Code Online (Sandbox Code Playgroud) python ×5
django ×3
javascript ×2
attributes ×1
css ×1
descriptor ×1
game-engine ×1
groovy ×1
html ×1
http ×1
ios ×1
ipad ×1
jenkins ×1
jquery ×1
nginx ×1
numpy ×1
pygame ×1
pytest ×1
python-2.7 ×1
react-select ×1
reactjs ×1
safari ×1
setattribute ×1
uwsgi ×1