我怎么能转换这个:
26.72773551940918
Run Code Online (Sandbox Code Playgroud)
进入这样的事情:
22°12'42"N
Run Code Online (Sandbox Code Playgroud)
这里的诀窍是坐标实际上是Latitude和Longitude,我只需要正确格式化它们.
我有一个有1个输入的模型.另外,我有一个收藏品.现在,当我向集合中添加模型时,我想将焦点设置为它的输入.确切地说,我需要将焦点放在新创建的模型视图的输入上.
但是,我似乎无法让它发挥作用.这是我的函数,它将模型的视图添加到集合视图中:
addOne: function(InvoiceItem) {
var view = new InvoiceItemView({model: InvoiceItem});
this.$('tr[data-id="'+InvoiceItem.get('after')+'"]').after(view.render().el);
this.$('tr[data-id="'+InvoiceItem.cid+'"]').css('background', 'green');
this.$('tr[data-id="'+InvoiceItem.cid+'"] input').focus();
},
Run Code Online (Sandbox Code Playgroud)
问题是,第三个电话:this.$('tr[data-id="'+InvoiceItem.cid+'"] input').focus();没有做任何事情.这很奇怪,因为我似乎只能在根元素上进行DOM操作tr,除此之外别无其他.
在我看来,jQuery不知道元素存在,这很奇怪,因为当我这样做时,alert(this.$('tr[data-id="'+InvoiceItem.cid+'"] input').length)我得到1,这表明元素存在.
我在这里做错了什么?
我有一个运行良好的命令,可以从我的所有.js和.html文件(仅是Underscore模板)中提取字符串。但是,它似乎不适用于翻译者注释。
例如,我的一个.js文件中有此文件:
/// TRANSLATORS: The word "manual" stands for manual process
gettext("manual");
Run Code Online (Sandbox Code Playgroud)
使用以下命令:
find . -iname '*.html' -o -iname '*.js' | xargs xgettext --language=Python --from-code=utf-8 --keyword=pgettext:1c,2 --keyword=npgettext:1c,2,3 --add-comments=/
Run Code Online (Sandbox Code Playgroud)
xgettext应该从.js文件中提取注释,并将其放入我的.po文件中,如下所示:
#. TRANSLATORS: The word "manual" stands for manual process
#: tax.js:200
msgid "manual" msgstr ""
Run Code Online (Sandbox Code Playgroud)
但事实并非如此。我在这里做错了吗,还是翻译注释在Python模式下不起作用?
编辑:我已经接受John Flatness的回答作为正确的答案,但是我确实找到了一种解决方法,使我仍然可以使用Python模式并提取翻译注释。这不是完美的,因为它实际上在注释中留下了一些语法:
在我的tax.js档案中:
/*
# This is a translator comment */
gettext("What is this?");
Run Code Online (Sandbox Code Playgroud)
运行以下命令:
find . -iname '*.html' -o -iname '*.js' | xargs xgettext --language=Python --from-code=utf-8 --keyword=pgettext:1c,2 --keyword=npgettext:1c,2,3 -c …Run Code Online (Sandbox Code Playgroud) 我想找到适当的状态代码返回,这是我到目前为止的想法:
GET /api/documents/1 - 文件存在,用户有权访问 - 200 OKGET /api/documents/2 - 文档存在,用户无权访问 - 403禁止访问GET /api/documents/3 - 文件不存在(无法检查是否有访问权限) - 404 Not Found?403禁止?GET /api/documents/a - id无效(应该是一个数字) - 400 Bad Request?404找不到?403禁止?我的后端(使用MongoDB)目前的问题是,我做的第一件事是检查用户是否可以通过检查文档ID来查看他有权访问的文档ID列表.如果在列表中找不到document_id,则会自动返回403 Forbidden.这有助于我避免首先从数据库中获取文档以查看用户是否可以访问它.
我不确定这里最好的做法是什么 - 我应该追求更好的HTTP状态代码(从而创建额外的数据库请求),还是最后2个案例(3和4)的403 Forbidden工作?
与几乎所有 Web 应用程序一样,我需要一种方法来引用我的 Node.js 应用程序中的当前用户。
我的登录/会话系统正在运行,但今天我注意到,当我在一个浏览器中登录我的应用程序并在另一个浏览器中查看它时,我可以看到与在第一个浏览器中看到的相同数据。
我目前将有关当前用户的信息存储在全局 app.current_user 对象中,但我现在意识到这是在所有请求/会话之间共享的,因为 node.js 是单线程的 - 因此,这是一个坏主意。
存储对当前用户的引用的正确方法是什么?当前用户不仅仅是用户数据的哈希值,而是一个 Mongoose 模型,所以我想存储在 cookie 中不是一个好主意?
顺便说一句 - 我还存储用户的设置和其他一些我不想在每次对用户及其设置执行某些操作时再次获取的内容(在单个请求期间可能会发生很多次)。我想你可能会说我正在内存中缓存当前用户。
假设我Invoice在SailsJS中有一个模型。它具有2个日期属性:issuedAt和dueAt。如何创建自定义验证规则,以检查到期日等于或大于发布日期?
我尝试创建自定义规则,但似乎无法访问规则内的其他属性。
module.exports = {
schema: true,
types: {
duedate: function(dueAt) {
return dueAt >= this.issuedAt // Doesn't work, "this" refers to the function, not the model instance
}
},
attributes: {
issuedAt: {
type: 'date'
},
dueAt: {
type: 'date',
duedate: true
}
}
};
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用新的Javascript国际化API,并想知道是否有办法获取Intl.NumberFormat实例的小数和千位(分组)分隔符?
resolvedOptions对象上有一个方法,但不提供符号.
如果有人想知道,那么对于en-US来说,这些将是逗号,和句号.,例如in 1,000.00.
javascript internationalization number-formatting ecmascript-5 ecmascript-intl
在我的webapp中,用户可以创建需要生成并在每个月的某些日期发送的定期发票.例如,可能需要在每个月的5号发送发票.
我正在使用Kue来处理我所有的后台工作,所以我也想在这种情况下这样做.
我目前的解决方案是每小时setInterval()创建一份processRecurringInvoices工作.然后,此作业将从数据库中查找所有定期发票,并generateInvoice为每个定期发票创建单独的作业.
然后,generateInvoice作业将实际生成发票,如果需要,还将创建sendInvoiceToEmail将通过电子邮件发送发票的作业.
目前这个解决方案对我来说很好,因为它有一个很好的关注点,但是,我有以下问题:
processRecurringInvoices工作上调用done()之前,我不确定是否应该等待所有"子"工作完成?processRecurringInvoices工作岗位,还是应该为每项工作单独处理?processRecurringInvoices或任何子作业仍在运行,processRecurringInvoices则不会再次创建作业?有点像独特的工作,还是互相排斥?我需要在PHP 5.2.17中模拟ROUND_HALF_DOWN模式 - 我无法升级服务器的PHP版本.任何想法如何实现这一目标?
基本思想是1.895变为1.89,而不是像通常用round()那样1.90.
编辑:这个功能似乎可以解决问题:
function nav_round($v, $prec = 2) {
// Seems to fix a bug with the ceil function
$v = explode('.',$v);
$v = implode('.',$v);
// The actual calculation
$v = $v * pow(10,$prec) - 0.5;
$a = ceil($v) * pow(10,-$prec);
return number_format( $a, 2, '.', '' );
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用主干创建发票行列表,其中一个按钮/事件是当您在现有行上单击"添加"时,它应该在单击"添加"按钮的正下方添加一个新行.
首先,我不确定是否应该在InvoiceItemView或InvoiceItemListView中处理此事件,其次,我不知道如何执行此操作.有谁能够帮我?
我试过这个:
$(function(){
// Invoice row
var InvoiceItem = Backbone.Model.extend({
// Set default values
defaults : {
name: "",
quantity: 1,
price: "",
total: ""
},
// Ensure each item has at least a quantity of one
initialize: function() {
this.set({ "quantity" : this.defaults.quantity });
},
// Delete item (row) from invoice
clear: function() {
this.destroy();
}
});
// Collection of Invoice Items ( rows )
var InvoiceItemList = Backbone.Collection.extend({
// Colelction's model
model: InvoiceItem,
// Use localStorage to …Run Code Online (Sandbox Code Playgroud) 有人可以帮助我改变这个
preg_match('/^(.*?)[#,\.0]+(.*?)$/',$patterns[0],$matches)
Run Code Online (Sandbox Code Playgroud)
进入Javascript等价?我试过了
matches = patterns[0].match('/^(.*?)[#,\.0]+(.*?)$/')
Run Code Online (Sandbox Code Playgroud)
但这会导致null ...
所以我正在尝试为我的REST API编写测试(构建在Express和Mongoose之上),但我遇到了一些麻烦.
我已经关注了很多示例和教程,这些示例和教程表明我的解决方案应该可行,但事实并非如此 - 我得到了一个 Error: global leak detected: path
似乎导致它的线是.post( '/api/invoices' )- 但我无法弄清楚为什么.
var app = require("../app").app,
request = require("supertest");
describe("Invoice API", function() {
it( "GET /api/invoices should return 200", function (done) {
request(app)
.get( '/api/invoices' )
.expect( 200, done );
});
it( "GET /api/invoices/_wrong_id should return 500", function (done) {
request(app)
.get( '/api/invoices/_wrong_id' )
.expect( 500, done );
});
it( "POST /api/invoices should return 200", function (done) {
request(app)
.post( '/api/invoices' )
.set( 'Content-Type', 'application/json' ) …Run Code Online (Sandbox Code Playgroud) javascript ×3
node.js ×3
backbone.js ×2
express ×2
php ×2
coordinates ×1
ecmascript-5 ×1
focus ×1
gettext ×1
http ×1
job-queue ×1
jquery ×1
kue ×1
match ×1
mocha.js ×1
mode ×1
mongodb ×1
mongoose ×1
preg-match ×1
python ×1
regex ×1
rest ×1
rounding ×1
sails.js ×1
setfocus ×1
worker ×1
xgettext ×1