小编the*_*imp的帖子

防止Sequelize在执行查询时将SQL输出到控制台?

我有一个功能来检索用户的个人资料.

app.get('/api/user/profile', function (request, response)
{
  // Create the default error container
  var error = new Error();

  var User = db.User;
  User.find({
    where: { emailAddress: request.user.username}
  }).then(function(user)
  {
    if(!user)
    {
      error.status = 500; error.message = "ERROR_INVALID_USER"; error.code = 301;
      return next(error);
    }

    // Build the profile from the user object
    profile = {
      "firstName": user.firstName,
      "lastName": user.lastName,
      "emailAddress": user.emailAddress
    }
    response.status(200).send(profile);
  });
});
Run Code Online (Sandbox Code Playgroud)

调用"find"函数时,它会在启动服务器的控制台上显示select语句.

Executing (default): SELECT `id`, `firstName`, `lastName`, `emailAddress`, `password`, `passwordRecoveryToken`, `passwordRecoveryTokenExpire`, `createdAt`, `updatedAt` FROM `Users` AS `User` …
Run Code Online (Sandbox Code Playgroud)

node.js sequelize.js

151
推荐指数
5
解决办法
7万
查看次数

键盘到位后移动UIScrollView

[编辑:]问题已经解决.我没有正确链接我的代表UIBuilder.代码很好!

我想在键盘出现时调整scrollview的大小.我去了开发人员文档并找到了这些信息.

http://developer.apple.com/library/ios/#documentation/StringsTextFonts/Conceptual/TextAndWebiPhoneOS/KeyboardManagement/KeyboardManagement.html#//apple_ref/doc/uid/TP40009542-CH5-SW1

在左侧"管理键盘".

在文档中,它显示了一些代码来检测键盘的大小,然后调整大小UIScrollView.我NSLog在函数代码中放了一条消息,- (void)keyboardWasShown:(NSNotification*)aNotification所以我看到函数实际上被调用了,但是当我尝试NSLog使用kbSize.height时,它的值总是为0.

为什么苹果为此目的提供的代码不起作用?

- (void)keyboardWasShown:(NSNotification*)aNotification
{
    NSDictionary* info = [aNotification userInfo];
    CGSize kbSize = [[info objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size;

    UIEdgeInsets contentInsets = UIEdgeInsetsMake(0.0, 0.0, kbSize.height, 0.0);
    scrollView.contentInset = contentInsets;
    scrollView.scrollIndicatorInsets = contentInsets;

    // If active text field is hidden by keyboard, scroll it so it's visible
    // Your application might not need or want this behavior.
    CGRect aRect = self.view.frame;
    aRect.size.height -= kbSize.height;
    if (!CGRectContainsPoint(aRect, activeField.frame.origin) …
Run Code Online (Sandbox Code Playgroud)

iphone keyboard objective-c ipad ios

15
推荐指数
2
解决办法
2万
查看次数

Kendo DataSource:如何取消更新请求

我有一个kendo UI网格和一个数据源.当我调用Update方法时,我测试一个变量,如果条件为false,我不想发送请求.

目前我有:

 $scope.MySource = new kendo.data.DataSource({
  update: {
            url: function (lista) {
                if (testVariable== true) {           
                    testVariable= false;
                    return "api/Liste/PutLista/" + lista.Id
                }
                else {
                    $scope.MySource.cancelChanges();
                }
            },
            type: "PUT",
            dataType: "json",
            beforeSend: function (req) {
                var auth = $window.sessionStorage.token;
                req.setRequestHeader('Authorization', 'Bearer ' + auth);
            }
Run Code Online (Sandbox Code Playgroud)

如果testVariable为false我取消更新,但我仍然看到ajax请求

http://localhost:61927/index.html with PUT method.
Run Code Online (Sandbox Code Playgroud)

如果testVariable是假的,我如何阻止请求?

javascript jquery kendo-ui kendo-grid

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

Doctrine Repository getEntityManager()确实返回空

我有一个我用Symfony2编写的应用程序.我创建了一个Account实体,并使用注释创建了一个名为AccountRepository的存储库.在AccountRepository对象中,我创建了一个函数来运行一些业务逻辑,该逻辑传递给外部供应商并在其站点上创建用户,并返回信息对我们来说,我可以将他们的用户与我们的帐户实体相关联.创建该用户的一部分包括通过信用卡令牌发送.然后,他们返回我想存储的一些有限的信用卡数据并与我们的帐户关联,因此在创建对象并插入适当的数据后我有一个实体AccountCard,我无法从存储库请求实体管理器并保持AccountCard执行$ em变量上的print_r什么也没有显示,但我读过的所有内容都告诉我,我应该能够做到这一点.我究竟做错了什么?

<?php

namespace Openbridge\CommonBundle\Entity\Repository;

use Doctrine\ORM\EntityRepository;

use Openbridge\CommonBundle\Entity\Account as Account;
use Openbridge\CommonBundle\Entity\AccountCard as AccountCard;
use Openbridge\CommonBundle\Entity\AccountAddress as AccountAddress;

/**
 * AccountRepository
 *
 * This class was generated by the Doctrine ORM. Add your own custom
 * repository methods below.
 */
class AccountRepository extends EntityRepository
{
    public function __construct()
    {

    }

    function createVendorUser(Account $account, $userData = array())
    {
        // Request new user from vendor code here. (this works)

        $ac = new AccountCard();
        // setters for $ac data here.

        // Get …
Run Code Online (Sandbox Code Playgroud)

php symfony doctrine-orm

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

终止输入循环

当用户点击'x'+ Enter时,我正试图找到一种终止循环的方法.我希望循环只在后台继续运行,直到用户取消它.

这些方面的东西:

while gets.chomp != 'x'

    puts 'looping...'

    sleep 1

end
Run Code Online (Sandbox Code Playgroud)

我是编程的初学者,并且已经广泛搜索了如何做到这一点,所以任何帮助都将深表感谢.

ruby

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

无法理解ruby错误

好的,所以我正在阅读"使用Rails进行敏捷Web开发"并开始使用软件仓库应用程序.对于那些有本书的人来说,这是第9.3章迭代D3:添加一个按钮.

在本节之前,我们创建了一个会话来保存我们的"购物车"

class ApplicationController < ActionController::Base

  protect_from_forgery

  private
    def current_cart
      Cart.find(session[:cart_id])
    rescue ActiveRecord::RecordNotFound
      cart = Cart.create
      session[:cart_id] = cart.id
      cart
    end
end
Run Code Online (Sandbox Code Playgroud)

使我们创建的任何控制器扩展ApplicationController都可以访问我们的购物车.

在本节中,我们编辑LineItemsController类的"create"函数,该函数扩展了ApplicationControler.

原始的create方法如下所示

def create
  @line_item = LineItem.new(params[:line_item])

  respond_to do |format|
    if @line_item.save
      format.html { redirect_to @line_item, notice: 'Line item was successfully created.' }
      format.json { render json: @line_item, status: :created, location: @line_item }
    else
      format.html { render action: "new" }
      format.json { render json: @line_item.errors, status: :unprocessable_entity }
    end
  end
end
Run Code Online (Sandbox Code Playgroud)

这本书说如果这样修改.

def create
  @cart = current_cart …
Run Code Online (Sandbox Code Playgroud)

ruby

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