小编Joh*_*ton的帖子

将事件侦听器添加到vanilla javascript中尚不存在的元素

在JQuery中我可以做到:

$(document).on("click","a.someBtn",function(e){
    console.log("hi");
});
Run Code Online (Sandbox Code Playgroud)

将事件侦听器添加到尚不存在的元素.我似乎无法弄清楚如何将事件监听器添加到尚未存在于vanilla javascript中的元素中.
以下不起作用:

query.addEventListener( "click", someListener );
Run Code Online (Sandbox Code Playgroud)

编辑

我想要做的是通过查询选择器比较项目.我正在选择尚不存在的元素querySelectorAll.它比仅仅检查标签名称更具动态性.

javascript jquery

10
推荐指数
1
解决办法
9080
查看次数

更改数字输入微调器的大小?

在一个数字输入上它有一个spinner,它有几个css属性,但我似乎无法找到一种方法来改变微调器本身的大小.我在说<input type='number'>.我试着找一些会改变尺寸的东西,但我找不到任何东西.我猜测的另一个问题是,每个操作系统上的每个浏览器都会有一个可能与spinner本身不同的实现.当我说微调器时,我正在谈论这个图像的突出部分.
在此输入图像描述

我无法使用JQuery UI微调器,因为我正在开发的大型应用程序使用不包含微调器的JQuery UI 1.8.升级会导致问题.

css html5

9
推荐指数
1
解决办法
7884
查看次数

从SQLalchemy和Flask中的相关列表中查询

我有User哪个has-one Person.所以User.person是一个Person.
我想User从列表中获取一个列表Person.

我尝试了以下方法:

>>> people = Person.query.filter().limit(3)
<flask_sqlalchemy.BaseQuery object at 0x111c69bd0>

>>> User.query.filter(User.person.in_(people)).all()
NotImplementedError: in_() not yet supported for relationships.  For a simple many-to-one, use in_() against the set of foreign key values.
Run Code Online (Sandbox Code Playgroud)

获取该列表中的Users 列表的最佳方法User.personpeople什么?

python sqlalchemy flask flask-sqlalchemy

8
推荐指数
1
解决办法
2144
查看次数

如何将 monaco-editor 从只读设置为可写?

在我的代码中,我创建了一个编辑器,如下所示:

this.monacoEditor = monaco.editor
  .create(
    document.getElementById('ide'), {
      model: null,
      readOnly: true,
      contextmenu: false,
    }
  );
Run Code Online (Sandbox Code Playgroud)

所以现在该编辑器是只读的。我如何更改this.monacoEditor为可写/可编辑?

javascript typescript monaco-editor

8
推荐指数
1
解决办法
6100
查看次数

Flask Gunicorn app无法让__name__等于'__main__'

我有这个来自/home/myname/myapp/app.py:

from flask import Flask

app = Flask(__name__)

print __name__

@app.route('/')
def index():
    return "Hello world!"

if __name__ == '__main__':
    print 'in if'
    app.run()
Run Code Online (Sandbox Code Playgroud)

当我跑:

$ gunicorn app:app -b 127.0.0.2:8000
Run Code Online (Sandbox Code Playgroud)

它说:

2013-03-01 11:26:56 [21907] [INFO] Starting gunicorn 0.17.2
2013-03-01 11:26:56 [21907] [INFO] Listening at: http://127.0.0.2:8000 (21907)
2013-03-01 11:26:56 [21907] [INFO] Using worker: sync
2013-03-01 11:26:56 [21912] [INFO] Booting worker with pid: 21912
app
Run Code Online (Sandbox Code Playgroud)

所以该__name__应用程序是app.不__main__喜欢我需要它来运行if语句.
我试着__init__.py在目录中放空.这是我的nginx sites-enabled default:

server …
Run Code Online (Sandbox Code Playgroud)

python nginx flask gunicorn

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

查询以检查SQLAlchemy中集合的大小是0还是空?

Person有一个Building.

Person 有很多 Group

我想要people从他们收藏中building没有任何人的所有人那里归还.也许我可以搜索拥有长度为0的组列表的人?就像是: Groupgroups

unassigned=Person.query.filter(Person.building==g.current_building,Person.groups.any()).all()
Run Code Online (Sandbox Code Playgroud)

python sqlalchemy flask

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

在WTForms中使用自定义属性创建选择域选项

我正在尝试创建一个SelectFieldSelectMultipleField允许我为其<option>标签添加属性.我试图添加像data-id或其他的属性data-____.我无法弄清楚如何做到这一点,因为它似乎只能为<select>标签本身而不是选项添加属性.
最终结果应该是这样的:

<select id="regularstuff-here" name="regular-name-here">
  <option value="1" data-id="somedata here" >Some Name here</option>
  <option value="2" data-id="somedata here" >Some Name here</option>
</select>
Run Code Online (Sandbox Code Playgroud)

我假设我必须创建一个自定义小部件.如果我查看WTForms的源代码,我会看到该select小部件调用:

html.append(self.render_option(val, label, selected))
Run Code Online (Sandbox Code Playgroud)

如果我看一下这个方法:

@classmethod
def render_option(cls, value, label, selected, **kwargs):
    options = dict(kwargs, value=value)
    if selected:
        options['selected'] = True
    return HTMLString('<option %s>%s</option>' % (html_params(**options), 
             escape(text_type(label))))
Run Code Online (Sandbox Code Playgroud)

因此,似乎您不能将任何额外的参数传递给呈现option标记的方法.

python flask wtforms

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

CoreBluetooth确实没有在Swift中调用DisodheralPeripheral

我99%确定我按照说明CoreBluetooth正确设置.无论我做什么,当我在我的iPad mini上运行这个应用程序时,蓝牙正在说它.它说它正在扫描设备,但绝对没有找到任何设备.如果我转到设备上的蓝牙菜单,我会看到其他设备被发现.我初始化了CBCentralManager.我安装好了centralManagerDidUpdateState.当确定蓝牙准备就绪时它就会打电话centralManager.scanForPeripheralsWithServices.所有这一切都正确发生.但我的代理功能centralManager(central: CBCentralManager!, didDiscoverPeripheral peripheral: CBPeripheral!, advertisementData: [NSObject : AnyObject]!, RSSI: NSNumber!)永远不会被调用.我的代码非常简单.也许我错过了一些东西,但我能够确认我的Macbook是BTLE设备而我的ipad mini也是BTLE设备.这是我的代码.

import UIKit
import CoreBluetooth

class ViewController: UIViewController, CBCentralManagerDelegate {

    var centralManager:CBCentralManager!
    var blueToothReady = false

    override func viewDidLoad() {
        super.viewDidLoad()
        startUpCentralManager()
    }

    func startUpCentralManager() {
        println("Initializing central manager")
        centralManager = CBCentralManager(delegate: self, queue: nil)
    }

    func discoverDevices() {
        println("discovering devices")
        centralManager.scanForPeripheralsWithServices(nil, options: nil)
    }

    func centralManager(central: CBCentralManager!, didDiscoverPeripheral peripheral: CBPeripheral!, advertisementData: [NSObject : AnyObject]!, RSSI: NSNumber!) { …
Run Code Online (Sandbox Code Playgroud)

bluetooth ios core-bluetooth bluetooth-lowenergy swift

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

如何从Swift的蓝牙特性中获取数据

我现在周围有一个Polar h7设备(它是BTLE)而且我已经完成了所有工作,但我很困惑如何获得BPM我们characteristic.value现在正在更新.我必须将一些字节转换为bpm ...

我的外设正在更新:

func peripheral(peripheral: CBPeripheral!, didUpdateValueForCharacteristic characteristic: CBCharacteristic!, error: NSError!) {
    if characteristic.UUID == CBUUID.UUIDWithString(heartRateChar) {
        getInfoAboutHeartRate(characteristic)
    }
}
Run Code Online (Sandbox Code Playgroud)

我收到有关心率的信息:

func getInfoAboutHeartRate(characteristic:CBCharacteristic) {
    println(characteristic.value)
    var bytes = characteristic.value.bytes
}
Run Code Online (Sandbox Code Playgroud)

我知道我需要将这些字节转换为BPM.
根据规格(这是我困惑的地方)在bluetooth.org,字节0要么是a 1还是0..如果是0心率值是a uint8,如果它是a 1那么它是a uint16和我可以从中获得BPM.
如何确定byte 0是a 1还是a 0?如何把它变成一个uint8uint16.如果我这样做,我会直接获得BPM,还是必须为此做其他事情?现在,BPM回归到了<16447d03>有意义的东西.

bluetooth characteristics ios btle swift

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

无法读取未定义的属性'indexOf'

我正在尝试在jquery中为几个日期选择器设置不同的选项.我的代码看起来像这样:

{foreach $cart->getItems() as $item}
    {if $item->action->prereservation}
        var disableDates = new Array();
        {if $item->action->hasVariants()}
        disableDates[{!$item->id}] = {$disabledDates[$item->action->id][$item->idVariant]};
        {else}
        disableDates[{!$item->id}] = {$disabledDates[$item->action->id]};
        {/if}

        if (disableDates[{!$item->id}].length !== 0) {
            $(".datepicker_"+'{$item->id}').datepicker({
                maxDate: new Date('{!$item->action->voucherTo|date: Y-m-d}'),
                beforeShowDay: function(date){
                    var string = jQuery.datepicker.formatDate('yy-mm-dd', date);
                    console.log(disableDates[{!$item->id}]) // result is undefined (but not for last iteration)
                    return [ disableDates[{!$item->id}].indexOf(string) == -1 ]
                }
            })
        } else {
            $(".datepicker_"+'{$item->id}').datepicker({
                maxDate: new Date('{!$item->action->voucherTo|date: Y-m-d}'),
            })
        }
    {/if}
{/foreach}
Run Code Online (Sandbox Code Playgroud)

但如果foreach中有多个项目,我的js控制台显示错误无法读取第一次迭代的未定义属性'indexOf',只有最后一次是好的.有人能帮帮我吗?

在我的代码我结合模板系统Latte和jquery.

这是我在浏览器中的最终代码:

var disableDates = new Array();
        disableDates[777955] = ["2014-07-25","2014-07-26","2014-07-27","2014-07-28","2014-07-29","2014-07-30","2014-07-31"]; …
Run Code Online (Sandbox Code Playgroud)

javascript jquery nette

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