小编Jai*_*era的帖子

使用主干管理服务器错误响应

我想知道在新的,更新或删除模型上管理服务器错误响应的最佳方法.此时服务器返回http状态代码#400.但Backbone中的默认错误处理程序未显示错误.

我怎样才能显示这些错误?

当服务器端验证失败时服务器是否返回http错误标题?(也许最好通过status ='ERROR'消息返回成功响应)

error-handling backbone.js

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

如何从另一个字典创建字典?

在Python dict中用另一些属性创建一个属性的最佳方法是什么dict

例如,假设我有以下内容dict:

dict1 = {
    name:          'Jaime',
    last_name:     'Rivera',
    phone_number:  '111111',
    email:         'test@gmail.com',
    password :     'xxxxxxx',
    token:         'xxxxxxx',
    secret_stuff:  'yyyyyyy'   
}
Run Code Online (Sandbox Code Playgroud)

我想获得

dict2 = {
    name:          'Jaime',
    last_name:     'Rivera',
    phone_number:  '111111',
    email:         'test@gmail.com'
}
Run Code Online (Sandbox Code Playgroud)

python dictionary

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

Backbone.Marionette的嵌套集合

我想创建一个日历集合,每天都是约会的集合.日对象的结构是:

day:{
    date:'08-06-2012',
    appointment: {
        time_begin:'12:55',
        time_end: '16:40',
        customer: 'Jaime'
    }
}
Run Code Online (Sandbox Code Playgroud)

此刻我有这个模型和观点:

// CALENDAR COLLECTION
App.Calendar.Collection = Backbone.Collection.extend({
    // MODEL
    model: App.Day.Model
}
Run Code Online (Sandbox Code Playgroud)

当日历集合从服务器获取数据时,它将获得完整的日期对象,包括约会.

// CALENDAR VIEW
App.Calendar.View = Backbone.Marionette.CompositeView.extend({
    // TEMPLATE
    template: Handlebars.compile(templates.find('#calendar-template').html()),
    // ITEM VIEW
    itemView: App.Day.View,
    // ITEM VIEW CONTAINER
    itemViewContainer: '#calendar-collection-block'
});

// DAY MODEL
App.Day.Model = Backbone.Collection.extend({
    // PARSE
    parse:function(data){
        console.log(data);
        return data;
    }
});

// DAY VIEW
App.Day.View = Backbone.Marionette.CompositeView.extend({
    collection: App.Day.Model,
    itemView: App.CalendarAppointment.View, //---->I NEED TO DEFINE THIS, NOT SURE HOW
    template: …
Run Code Online (Sandbox Code Playgroud)

backbone.js marionette

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

使用GIT获取文件的最后更改

我有一个带有查询的一些sql文件的项目.每个开发人员都会增加这些文件的内容(它们永远不会删除内容).

我需要一个git命令来获取所有开发人员在我上次提交时生成的所有.sql文件的所有新行.

git

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

使用Backbone.Marionette在CompositeView上渲染事件之后

我有一个带有搜索面板和结果数据集合的Marionette CompositeView.

我想在以下情况下调用函数:

  • 搜索面板已呈现.
  • 该集合尚未呈现.
  • 渲染集合时不应调用此函数.

我是这样做的:(但"afterRender"函数被调用两次)

// VIEW
App.MyComposite.View = Backbone.Marionette.CompositeView.extend({
    // TEMPLATE
    template: Handlebars.compile(templates.find('#composite-template').html()),
    // ITEM VIEW
    itemView: App.Item.View,
    // ITEM VIEW CONTAINER
    itemViewContainer: '#collection-block',

    //INITIALIZE
    initialize: function() {        
        this.bindTo(this,'render',this.afterRender);
    },

    afterRender: function () {
        //THIS IS EXECUTED TWICE...
    }

});
Run Code Online (Sandbox Code Playgroud)

我怎样才能做到这一点?

==========================编辑======================= ===========

我这样解决了,如果你有观察请告诉我.

// VIEW
App.MyComposite.View = Backbone.Marionette.CompositeView.extend({

    //INITIALIZE
    initialize: function() {        
        //this.bindTo(this,'render',this.afterRender);
        this.firstRender = true;
    },

    onRender: function () {
        if (firstRender) {
            //DO STUFF HERE..............
            this.firstRender = false;         

        }
    }

});
Run Code Online (Sandbox Code Playgroud)

backbone.js marionette

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

带把手的 Nodemailer 无法正确显示样式

我正在使用 nodemailer 和车把发送电子邮件,我正确收到电子邮件,但未应用样式。

这是我发送电子邮件的代码:

    const hbsConfig = {
        viewEngine: {
            extName: '.hbs',
            partialsDir: path.join(__dirname, '../../../../src/modules/hq-nd/templates/'),
            layoutsDir: path.join(__dirname, '../../../../src/modules/hq-nd/templates/'),
            defaultLayout: ''
        },
        viewPath: path.join(__dirname, '../../../../src/modules/hq-nd/templates/'),
        extName: '.hbs'
    };

    const transporter = nodemailer.createTransport({
        host: 'smtp.sendgrid.net',
        port: 465,
        secure: true,
        auth: {
            user: 'zzz',
            pass: process.env.SENDGRID_SECRET,
        },
    });
    transporter.use('compile', hbs(hbsConfig));
    const email = {
        from: "Boxtribe <123@gmail.com>",
        to: params.username,
        subject: 'Reset your zzz Password',
        template: 'forgot-password',
        context: {
            ...user,
            token: tokenRes.token,
            url: process.env.HARMONY_URL
        }
    };
    const response = await transporter.sendMail(email as Mail.Options);
Run Code Online (Sandbox Code Playgroud)

这是我的模板: …

javascript node.js handlebars.js typescript nodemailer

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

Python:'module'对象不可调用

我定义了一个异常类

#####UNIQUE CONSTRAINT EXCEPTION#########################################################3
class UniqueConstraintException (Exception):
    def __init__(self, value):
        self.value = value

    def __str__(self):
        return repr('Failed unique property. Property name: ' + self.value)
Run Code Online (Sandbox Code Playgroud)

文件名是:"UniqueConstraintException.py"和包名:"exception"

我正在以这种方式导入和使用它:

from exception import UniqueConstraintException

raise UniqueConstraintException(prop_key)
Run Code Online (Sandbox Code Playgroud)

并得到此错误:

TypeError: 'module' object is not callable
Run Code Online (Sandbox Code Playgroud)

我究竟做错了什么?

python exception

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

使用Postgres测试文件是否存在

我需要创建一个函数来测试文件是否存在postgres.我是用C语言做的,但我遇到了问题.代码是:

#include "postgres.h"
#include <string.h>
#include "fmgr.h"
#include <stdio.h>
#include<sys/stat.h>

#ifdef PG_MODULE_MAGIC
PG_MODULE_MAGIC;
#endif

/* by value */

PG_FUNCTION_INFO_V1(file_exists);
Datum
file_exists (PG_FUNCTION_ARGS)
{
   text *fileName= PG_GETARG_TEXT_P(0);

   struct stat buf;
   int i = stat(fileName, &buf);
     /* File found */
     if ( i == 0 )
     {
       PG_RETURN_INT32(1);
     }
     PG_RETURN_INT32(0);

}
Run Code Online (Sandbox Code Playgroud)

我认为问题在于"stat"函数中的第一个参数,因为fileName是一个文本而且这个函数接收一个char.

这是我第一次编写C代码,所以也许一切都是错的.

c postgresql

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

将笔触效果添加到DIV边框

我需要创建一个带自定义边框的HTML div.根据设计师的说法,边框的半径为3px,行程为8px,颜色为f7f7f7,位置在外

到目前为止我所拥有的是:

div#content {
    padding                 :   10px 20px;
    border-style                :   solid;
    border-width                :   8px;
    border-color                :   #F7F7F7;
    -webkit-border-radius       :   3px;
    -moz-border-radius          :   3px;
    border-radius               :   3px;

}
Run Code Online (Sandbox Code Playgroud)

我真的不知道中风效果是什么以及如何用css做到这一点.

html css css3

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