我有一个用户输入GMT的时间戳.
然后我想在gmt,cet,pst,est中显示该时间戳.
感谢我下面的帖子,它完美无缺!
public static function make_timezone_list($timestamp, $output='Y-m-d H:i:s P') {
$return = array();
$date = new DateTime(date("Y-m-d H:i:s", $timestamp));
$timezones = array(
'GMT' => 'GMT',
'CET' => 'CET',
'EST' => 'EST',
'PST' => 'PST'
);
foreach ($timezones as $timezone => $code) {
$date->setTimezone(new DateTimeZone($code));
$return[$timezone] = $date->format($output);
}
return $return;
}
Run Code Online (Sandbox Code Playgroud) import React from 'react';
export default class UIColours extends React.Component {
displayName = 'UIColours'
render() {
const colours = ['black', 'red', 'white', 'orange', 'green', 'yellow', 'blue', 'darkblue', 'lilac', 'purple', 'darkPurple'];
return (
<div className="ui-colours-container row bg-white">
<div className="col-md-16 col-xs-16 light">
<div className="color-swatches">
{colours.map(function(colour, key) {
return (
<div key={key} className={'strong color-swatch bg-' + colour}>
<p>{colour}</p>
</div>
);
})}
</div>
</div>
</div>
);
}
}
Run Code Online (Sandbox Code Playgroud)
12:26错误意外的函数表达式prefer-arrow-callback
我查看了地图文档,找不到多个参数的好例子.
通过jQuery,是否有可能以不同的方式为选择选择多选?
我遇到的问题是我有一个普通的js调用,它会对id做一些事情.但是在某些页面上它有不同的用途.
因此,我想要认识到这种差异.
$("select#categories[multiselect]").doOneThing; //multiselect
$("select#categories").doAnotherThing; //normal single select
Run Code Online (Sandbox Code Playgroud)
可能?
我的红宝石模型,如下:
class User
include Mongoid::Document
field :first_name, type: String
field :birthdate, type: Date
validates :first_name, :birthdate, :presence => true
end
Run Code Online (Sandbox Code Playgroud)
输出一个像这样的对象:
{
_id: {
$oid: "522884c6c4b4ae5c76000001"
},
birthdate: null,
first_name: null,
}
Run Code Online (Sandbox Code Playgroud)
我的骨干项目不知道如何处理_id.$ oid.
我发现这篇文章和代码:
https://github.com/rails-api/active_model_serializers/pull/355/files
module Moped
module BSON
class ObjectId
alias :to_json :to_s
end
end
end
Run Code Online (Sandbox Code Playgroud)
I have no idea where to put this, and how to invoke it on the model output, so I tried inside:
/config/initializers/secret_token.rb
I'm new to Ruby and Rails and have no idea …
目前我发现我必须为不同的模块重复部分.
我想有一个案例目录,供所有部分访问.
有没有人有这样做的好方法?
谢谢
$.ajax({
type: 'POST',
url: api_url+'client/'+client.id+'.json',
data: {
_method: 'delete',
id: client.id
},
success: function(data) {
$('#delete-client').html('Success');
},
error: function(data) {
$('#delete-client').css('color', 'red');
$('#delete-client').html('Error');
}
});
Run Code Online (Sandbox Code Playgroud)
在错误:函数jquery将接收具有500头状态的这个json对象
{"errors":{"code":777,"message":"Method requested does not yet exist","data":[]}}
Run Code Online (Sandbox Code Playgroud)
但是,如果我使用data.errors.message它不会显示错误.当我在console.log中使用返回对象时,它会在chromes开发框中显示一个包含不同事件的巨大对象
固定
var error = jQuery.parseJSON(jqXHR.responseText);
$('#delete-client').html(error.errors.message);
Run Code Online (Sandbox Code Playgroud) *在底部更新*
在寻找不存在的用户时,我得到:
UsersController#show中的Mongoid :: Errors :: DocumentNotFound
问题:找不到具有id(s)22的类User的文档.摘要:当使用id或id数组调用User.find时,每个参数必须与数据库中的文档匹配,否则将引发此错误.搜索的是id(s):22 ...(总共1个)并且找不到以下ID:22.解决方案:搜索数据库中的id或将Mongoid.raise_not_found_error配置选项设置为false,这将导致返回nil而不是在搜索单个id时引发此错误,或者在搜索倍数时仅返回匹配的文档.
但是我将raise_not_found_error设置为false
mongoid.yml
development:
adapter: 'mongoid'
# Configure available database sessions. (required)
sessions:
# Defines the default session. (required)
default:
# Defines the name of the default database that Mongoid can connect to.
# (required).
database: blog_development
# Provides the hosts the default session can connect to. Must be an array
# of host:port pairs. (required)
hosts:
- localhost:27017
options:
allow_dynamic_fields: false
identity_map_enabled: true
include_root_in_json: true
include_type_for_serialization: true
# Note this can …Run Code Online (Sandbox Code Playgroud) 我正在使用Backbone Marionettes CollectionView.我试图表明集合正在加载,todo所以我使用emptyView来显示一个加载器.
然而,这是错误的逻辑,因为有时候集合是空的,因此它变成了一个破碎的加载器.
我尝试使用这个脚本,但它没有用:https://github.com/surevine/marionette-loadingview-plugin
有没有人有更好的解决方案?继承我目前的代码:
//loadingview
define(["marionette", "text!app/templates/loading.html"], function(Marionette, Template) {
"use strict";
return Backbone.Marionette.ItemView.extend({
template: Template
});
})
//collection
define(["marionette", "text!app/templates/events/collection.html", "app/collections/events", "app/views/events/item", 'app/views/loading'], function (Marionette, Template, Collection, Row, LoadingView) {
"use strict"
return Backbone.Marionette.CompositeView.extend({
template: Template,
itemView: Row,
itemViewContainer: "ul",
emptyView: LoadingView,
initialize: function () {
this.collection = new Collection()
return this.collection.fetch()
}
})
})
//item
define(["marionette", "text!app/templates/events/item.html"], function(Marionette, Template) {
"use strict";
return Backbone.Marionette.ItemView.extend({
template: Template,
tagName: "li"
})
})
Run Code Online (Sandbox Code Playgroud) 我有一个白板任务让我在面试中难住了,但是我已经写了一个解决方案并想知道是否有人在我迭代时对其进行了改进,而面试官说不要。这两个数组必须以array1[0], array2[0], array1[1], array2[1]...(见expectedResult)等的顺序合并
const options = [[1, 12, 5], ["a", "b", "c", "d", "e"]]
const expectedResult = [1, "a", 12, "b", 5, "c", "d", "e"]
function mergeArrays(first, second) {
let returnArray = []
first.forEach((value, key) => {
returnArray.push(value)
if (second[key]) returnArray.push(second[key])
if (!first[key + 1] && second[key + 1]) {
returnArray.push(
...second.slice(key + 1, second.length)
)
}
})
return returnArray
}
const result = mergeArrays(options[0], options[1])
console.log(result.toString() === expectedResult.toString(), result)Run Code Online (Sandbox Code Playgroud)
javascript ×4
backbone.js ×2
jquery ×2
mongoid ×2
ruby ×2
ajax ×1
arrays ×1
ecmascript-6 ×1
eslint ×1
marionette ×1
partials ×1
php ×1
reactjs ×1
svn ×1
timezone ×1