小编Al *_*Tsm的帖子

document.body.scrollTop Firefox返回0:只有JS

纯javascript中的任何替代品?

以下适用于歌剧,铬和野生动物园.尚未在资源管理器上测试过:

http://monkey-me.herokuapp.com

https://github.com/coolcatDev/monkey-me-heroku/blob/master/static/js/myscripts.js

在页面加载时应向下滚动到div'.content':

var destiny = document.getElementsByClassName('content');
var destinyY = destiny[0].offsetTop;
scrollTo(document.body, destinyY, 200);

function scrollTo(element, to, duration) {
    if (duration <= 0) return;
    var difference = to - element.scrollTop;
    var perTick = difference / duration * 2;

    setTimeout(function() {
        element.scrollTop = element.scrollTop + perTick;
        scrollTo(element, to, duration - 2);
    }, 10);
};
Run Code Online (Sandbox Code Playgroud)

javascript firefox cross-browser

66
推荐指数
3
解决办法
4万
查看次数

Flask-SQLAlchemy查询连接关系表

我正在使用Flask和SQLAlchemy构建一个应用程序.我基本上有3个表:用户,友谊和bestFriends:

用户可以拥有许多朋友,但只有一个最好的朋友.所以我希望我的模型是关系型的."一对多"用于"用户"和"友谊"之间的关系以及"用户"和"最佳朋友"之间的"一对一"关系.

这是我的模特:

from app import db
from sqlalchemy.orm import relationship, backref
from sqlalchemy import Table, Column, Integer, ForeignKey
from sqlalchemy.ext.declarative import declarative_base

class users(db.Model):

    __tablename__ = "Users"

    id = db.Column(db.Integer, primary_key=True)
    userName = db.Column(db.String, nullable=False)
    userEmail = db.Column(db.String, nullable=False)
    userPhone = db.Column(db.String, nullable=False)
    userPass = db.Column(db.String, nullable=False)

    friendsR = db.relationship('friendships', backref='friendships.friend_id', primaryjoin='users.id==friendships.user_id', lazy='joined')

    def __init__(self, userName, userEmail, userPhone, userPass):
        self.userName = userName
        self.userEmail = userEmail
        self.userPhone = userPhone
        self.userPass = userPass

    def __repr__(self):
        return '{}-{}-{}-{}'.format(self.id, self.userName, self.userEmail, self.userPhone)

class …
Run Code Online (Sandbox Code Playgroud)

join sqlalchemy flask flask-sqlalchemy

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

在Flask应用程序的单元测试期间无法创建测试客户端

我试图找出如何对从中获取变量值的函数运行测试session['user_id'].这是具体的测试方法:

def test_myProfile_page(self):
    with app.test_client() as c:
        with c.session_transaction() as sess:
            sess['user_id'] = '1'

    rv = c.get('/myProfile')
    assert 'My Profile' in rv.data
Run Code Online (Sandbox Code Playgroud)

这是正在测试的视图:

@app.route('/myProfile')
def myProfile():
    if not session.get('logged_in'):
        return render_template('login.html')
    else:
        profileID = session['user_id']
        userList = users.query.filter_by(id=profileID).all()
        flash('My Profile')
        return render_template('myProfile.html', userList=userList)
Run Code Online (Sandbox Code Playgroud)

这是整个测试文件:

import os
import app
import unittest
import tempfile

class AppTestCase(unittest.TestCase):
    def setUp(self):
        self.db_fd, app.app.config['DATABASE'] = tempfile.mkstemp()
        app.app.config['TESTING'] = True
        self.app = app.app.test_client()

    def tearDown(self):
        os.close(self.db_fd)
        os.unlink(app.app.config['DATABASE'])

    def test_profile_page(self):
        rv = self.app.get('/profile1')
        assert 'Profile' in …
Run Code Online (Sandbox Code Playgroud)

python unit-testing flask

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

AngularJS:动态表单生成

我需要一种基于文档结构生成动态表单的方法,以便更新其属性的现有值或向多值属性添加值.

我有一个角度控制器,接收文档类名称和id并拉出该类的特定文档.

控制器读取文档并保存数据,如属性数量,属性类型,属性是否为多值以及值.

每个类的属性数量,属性类型都不同.

以下是我的控制器为特定类的特定文档生成的数据示例:

 CLASS/id {cid: "Disease/54d49a8c3b70f6cce63dc475"}
 N° ATTRIBUTES:3(without counting multivalues of the same attribute)


 /////////////////////////////////////////////////////////////////////////////////////////////
 ATTRIBUTE NAME:displayName
 /////////////////////////////////////////////////////////////////////////////////////////////
 ATTRIBUTE DATA TYPE:text
 MULTI VALUE ATTRIBUTE:0(not multivalue field)
 ATTRIBUTE N° OF VALUES:1(existing n° of values at the moment)
 ATRIBUTE ARRAY POSITION:0 ---> value displayName #1


 /////////////////////////////////////////////////////////////////////////////////////////////
 ATTRIBUTE NAME:identifier
 /////////////////////////////////////////////////////////////////////////////////////////////
 ATTRIBUTE DATA TYPE:text
 MULTI VALUE ATTRIBUTE:1(multivalue field)
 ATTRIBUTE N° OF VALUES:1(existing n° of values at the moment)
 ATRIBUTE ARRAY POSITION:0 ---> value identifier #1


 /////////////////////////////////////////////////////////////////////////////////////////////
 ATTRIBUTE NAME:r
 /////////////////////////////////////////////////////////////////////////////////////////////
 ATTRIBUTE DATA TYPE:date …
Run Code Online (Sandbox Code Playgroud)

javascript angularjs angularjs-directive angularjs-scope angularjs-ng-repeat

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

指针事件上的css过渡延迟不起作用

我希望链接在容器被悬停后恢复被点击的能力。

在下面的示例中,当父 div 悬停时,我对链接的可见性应用延迟。

但是我不能将相同的理念应用于指针事件属性。

http://jsfiddle.net/coolcatDev/trLf02e2/4/

html:

<div class="a">
    <a href="#">Some link</a><br>
    <a href="#">Some link</a><br>
    <a href="#">Some link</a><br>
    <a href="#">Some link</a><br>
    <a href="#">Some link</a>
</div>

<div class="b">
    <a href="https://google.com">Some link</a><br>
    <a href="https://google.com">Some link</a><br>
    <a href="https://google.com">Some link</a><br>
    <a href="https://google.com">Some link</a><br>
    <a href="https://google.com">Some link</a>
</div>
Run Code Online (Sandbox Code Playgroud)

css:

.a, .b{
    border:2px solid grey;
}

.a a{
    visibility:hidden;
}

.a:hover a{
    visibility:visible;
    transition-delay:1s;
}

.b a{
    pointer-events:none;
    cursor:default;
}

.b:hover a{
    pointer-events:auto;
    cursor:pointer;
    color:red;
    transition-delay:2s ;
}
Run Code Online (Sandbox Code Playgroud)

html css css-transitions

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

改善慢角指令

我有一个页面,根据窗口宽度呈现表视图或div/blocks视图.但是观点之间的交流发生得非常缓慢.也许我不是以最好的方式做事?

我基本上有2个范围变量(块和表,设置为true或false)在控制器中定义.

我有一个在窗口调整大小时触发的指令,根据这个宽度,我将控制器范围变量设置为true或false.

模板根据范围变量的ng-if条件呈现表或div.

模板:

<div view-controll ng-controller="viewController">

  <div ng-if="table==true" id="tableView">
    <div class="table-responsive">
      <table class="table table-striped table-condensed">
         <tbody>
          <tr class="tableRowsDocs" ng-repeat="dbo in rows">
            //data
          </tr>
        </tbody>
      </table>
    </div>
  </div>

  <div ng-if="block==true" id="mobileView">
    <div class="col-xs-12 col-sm-6 col-md-3" ng-repeat="dbo in rows">
     //data
    </div>
  </div>

</div>
Run Code Online (Sandbox Code Playgroud)

控制器:

 app.controller('viewController', function($scope) {
      $scope.block = false;
      $scope.table = true;
    });
Run Code Online (Sandbox Code Playgroud)

指示:

app.directive('viewControll', ['$window', function($window) {
    return {
        link: function(scope, elem, attrs) {
            scope.onResize = function() {               
                if (window.innerWidth > 700){
                  scope.block = false;
                  scope.table = true; …
Run Code Online (Sandbox Code Playgroud)

javascript angularjs angularjs-directive

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

500内部服务器错误Heroku

我有一个用于学习目的的系统,用于Flask-SQLAlchemy并部署在Heroku上(python/postgresql:

http://monkey-me.herokuapp.com/

https://github.com/coolcatDev/monkey-me

我的应用程序在本地工作正常,我通过14次成功通过测试对其功能和用例进行了单元测试.

当我部署一切似乎完美.它部署了我定义的环境变量APP_SETTINGS >>> config.BaseConfig,我运行db_create.py脚本来初始化db.我创建了一些用户:

username-userpassword:

Alex-passwordAlex
Jack-passwordJack
Sara-passwordSara
Run Code Online (Sandbox Code Playgroud)

但是缺少一件事......我从主导航栏转到用户页面,我收到一个5oo内部服务器错误说:

The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there is an error in the application.
Run Code Online (Sandbox Code Playgroud)

我在app.py上的应用代码具有以下调试模式:

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

但是没有显示进一步的错误.

请注意,如果我在heroku上访问系统并且我已经注销,如果我转到用户,我应该重定向到登录页面,这样我已经调试了多远......

如果我将heroku上的环境变量LAUNCHY_DEBUG设置为true或false,那么一切都会变得疯狂并出现新问题......就像我无法删除用户一样,配置文件图像不会加载....

如果我从heroku中删除LAUNCHY_DEBUG var,则新问题(图像不会加载,无法删除用户..)会在用户页面的原始500错误中保留.

提前感谢您对调试的任何建议

python sqlalchemy heroku flask

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

Javascript sort()数组混合数据类型

如果我有一个像这样的数组:

["23", "765", "sfasf", "2.3E-3", "2.3cE-3"]
Run Code Online (Sandbox Code Playgroud)

如何订购,以便数字(小数,浮点数或科学记数法)按升序排序,并且在那些不是数字的字符串之后(例如"sfasf"或"2.3cE-3")?

示例数组的预期顺序:

["2.3E-3", "23", "765", "2.3cE-3", "sfasf"]
Run Code Online (Sandbox Code Playgroud)

无法转换为数字的字符串的顺序无关紧要,它们必须在最后.

答案解答:

 $scope.cleanAndOrder = function(dbo, fieldName) {
    var textareaId = "textarea"+"_"+fieldName ;
    var textarea= document.getElementById(textareaId);

    //(+b && (+a!=a)) : return true (converted to 1) if b is a number and a isn't
    //(a-b) : then compare the numbers if the first comparaison isn't enough
    textarea.value = dbo.attributes[fieldName].sort(function(a,b){ return (+b && !+a) || (a-b) }).join("\n");
    var lines = textarea.value.split("\n");
    textarea.setAttribute('rows', lines.length +2);
 }
Run Code Online (Sandbox Code Playgroud)

javascript arrays sorting

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

如果页面之前滚动,则拖动时的角度ui可排序偏移量

我发现如果页面是可滚动的,滚动后如果要拖放项目(为了对ng-repeat列表进行排序),则拖动的元素在y轴上显示的偏移量与我滚动的距离相同在拖动元素之前在页面下方.

我正在使用:https: //github.com/angular-ui/ui-sortable

这里记录了这个问题:https: //github.com/angular-ui/ui-sortable/issues/286

我似乎无法调用ui.item.sort('refreshPosition')方法.无论是通过编辑原始代码还是在我自己的控制器中确定是否应该这样做!?

这是我的相关模板代码:

    <script type="text/ng-template" id="form_field_ref2">
  <div ng-init="tmp = dbo.get(attobj.name)" ng-controller="sortController">
   <!-- <div ng-model="tmp" ui-sortable="{ 'ui-floating': 'auto'}">-->
    <div ng-model="tmp" ui-sortable="sortableOptions">
      <div ng-repeat="dbo2 in dbo.get(attobj.name) track by $index" id="sort_{{$index}}" style="float:left; padding-right: 3px; padding-bottom: 5px;">
        <div class="tag sortableTag">
          <a href="#/view/{{ dbo2.cid }}" target="_blank">{{ dbo2.displayName() }}</a>
          <a href="" class="glyphicon glyphicon-remove" ng-click="dbo.removeValue(attobj.name, $index)"></a>
        </div>
      </div>

    </div>
  </div>

  <div ng-include="'typeaheadtemplate2'" style="width: 100%;"></div>
</script>
Run Code Online (Sandbox Code Playgroud)

控制器:

app.controller('sortController', function ($scope) {

  $scope.sortableOptions = {
    'ui-floating': 'auto',
    activate: function() {
        console.log("activate"); …
Run Code Online (Sandbox Code Playgroud)

javascript css jquery jquery-ui angular-ui-sortable

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