在设计状态形状的章节中,文档建议将您的状态保存在由ID键入的对象中:
将每个实体保存在以ID作为密钥存储的对象中,并使用ID从其他实体或列表中引用它.
他们继续陈述
将应用程序的状态视为数据库.
我正在处理状态形状以获取过滤器列表,其中一些将打开(它们显示在弹出窗口中),或者已选择选项.当我读到"将应用程序的状态视为数据库"时,我考虑将它们视为JSON响应,因为它将从API(本身由数据库支持)返回.
所以我一直在考虑它
[{
id: '1',
name: 'View',
open: false,
options: ['10', '11', '12', '13'],
selectedOption: ['10'],
parent: null,
},
{
id: '10',
name: 'Time & Fees',
open: false,
options: ['20', '21', '22', '23', '24'],
selectedOption: null,
parent: '1',
}]
Run Code Online (Sandbox Code Playgroud)
但是,文档建议更像一种格式
{
1: {
name: 'View',
open: false,
options: ['10', '11', '12', '13'],
selectedOption: ['10'],
parent: null,
},
10: {
name: 'Time & Fees',
open: false,
options: ['20', '21', '22', '23', '24'],
selectedOption: null,
parent: …
Run Code Online (Sandbox Code Playgroud) 我已经设置了Amazon S3来为我的静态站点提供服务speakeasylinguistics.com
.所有的DNS东西似乎都运行正常,因为dig +recurse +trace www.speakeasylinguistics.com
输出正确的DNS信息.
但是当您使用端点在浏览器中访问该站点时,index.html
页面将下载而不是被提供.我该如何解决?
我试过Chrome,Safari,FF.它发生在所有这些上.我使用亚马逊的演练来托管自定义域名.
strptime
和之间有什么区别strftime
?我看到这strptime
是DateTime
类strftime
中的一个方法,并且是类中的一个方法Time
.
在测试React组件时,我正在阅读文档并找到了scryRenderedDOMComponentsWithClass
.我无法理解这个组件的功能,因为它是不可发声的,所以我不明白它是如何命名映射到它正在做的事情的心智模型.(有许多相关的名称,例如scryRenderedDOMComponentsWithTag
.)
scry
这个方法名称的部分是指什么?害怕?匆匆?这个名字试图说明什么概念?
让我首先确认这不是重复(因为那里发布的答案没有解决我的问题).这篇文章基本上是我的确切问题:Capybara无法在Stripe模式中找到表单字段来填充它们.
这是我的水豚规格:
describe 'checkout', type: :feature, js: true do
it 'checks out correctly' do
visit '/'
page.should have_content 'Amount: $20.00'
page.find('#button-two').click_button 'Pay with Card'
Capybara.within_frame 'stripe_checkout_app' do
fill_in 'Email', with: 'example@example.com'
fill_in 'Name', with: 'Nick Cox'
fill_in 'Street', with: '123 Anywhere St.'
fill_in 'ZIP', with: '98117'
fill_in 'City', with: 'Seattle'
click_button 'Payment Info'
fill_in 'Card number', with: '4242424242424242' #test card number
fill_in 'MM/YY', with: '02/22'
fill_in 'CVC', with: '222'
click_button 'Pay'
end
page.should have_content 'Thanks'
end
end
Run Code Online (Sandbox Code Playgroud)
该规范中的文字是我最近的尝试. …
使用这git diff --shortstat my_branch master
是一个很好的方式来告诉有多少文件更改以及插入和删除.我读了git diff文档,但是我找不到一种方法来告诉my_branch
和之间的提交数量master
.那存在吗?
也许这不是一个问这个问题的好地方,但我会尽量使其尽可能客观和负责.
我一直在玩Angular.js而且非常喜欢它,但我对它的哲学有疑问.这是一个来自Angular站点的控制器代码片段.
<div ng-controller="TodoCtrl">
<span>{{remaining()}} of {{todos.length}} remaining</span>
[ <a href="" ng-click="archive()">archive</a> ]
<ul class="unstyled">
<li ng-repeat="todo in todos">
<input type="checkbox" ng-model="todo.done">
<span class="done-{{todo.done}}">{{todo.text}}</span>
</li>
</ul>
<form ng-submit="addTodo()">
<input type="text" ng-model="todoText" size="30"
placeholder="add new todo here">
<input class="btn-primary" type="submit" value="add">
</form>
</div>
Run Code Online (Sandbox Code Playgroud)
这基本上是HTML
使用了Angular指令.我发现可能会引起怀疑的是:<a href="" ng-click="archive()">archive</a>
.
当Jeffrey Zeldman编写Designing With Web Standards时,将标记(HTML),表示(CSS)和交互(JS)分离到不同的文件中以实现可维护性成为一种最佳实践.
我的问题是,Angular如何不违反?我实际上非常喜欢它,并且发现它非常强大,但是将click事件绑定到a
标记中的元素之间的区别是什么,并编写这些前Web标准代码的痕迹:
<a href='#' onClick='showAlert()'>Click here</a>
<script>
var showAlert = function(){
alert('hey');
}
</script>
Run Code Online (Sandbox Code Playgroud)
除了使用框架的个人经验之外,有用的答案可能是指文档.
我有一个非常简单的弹出对话框,由我的Laravel应用程序中的JavaScript驱动.实际上,在单击时,会在弹出窗口div
中添加一个类,该类使用CSS过渡将其不透明度从0更改为1.
这是我的测试:
public function testCantFindCodePopup()
{
$customer = $this->createCustomer();
$this->fillOutEmailAndDob($customer);
$this->visit('/product-codes/new')
->dontSee("Still can't find your code?");
$this->click('Can\'t find your code?');
sleep(0.5);
$this->see("Call customer service");
}
Run Code Online (Sandbox Code Playgroud)
过渡需要300毫秒,所以我认为sleep
500毫秒将解决问题,但没有骰子.
实际上,测试在dontSee("Still can't find your code?")
部分失败,即使该文本位于弹出窗口内部,该弹出窗口已display: none
在加载时设置.
我做错了什么,或者PHPUnit不知道像capybara那样的CSS和JavaScript (因为它在无头浏览器中运行).
如果我不能将PHPUnit用于这种类型的集成测试,那么我可以使用类似的东西吗?请注意,我在PHPUnit中有大约70个其他测试,所以无论其他工具是什么,它都不能代替批发; 理想情况下,它与我的PHPUnit测试一起存在.
刀片模板的相关部分:
<div class="form-control">
<label for="product-code">Enter Your{{$second}}Code</label>
<input type="text" id="product-code" name="product-code" />
</div>
<button class="btn btn-dark" type="submit">Submit</button>
<span class="label-explanation js__popup-toggle">Can't find your code?
<div class='popup'>
<span class="popup__close">×</span>
<img src="/assets/images/find-code-pop-up.png" alt="[alt text]" /> …
Run Code Online (Sandbox Code Playgroud) 我有一个简单的控制器,我已经响应了两个html
和json
.我正在使用json
Backbone应用程序的响应.一切都按预期工作,除了当我单击使用该show
方法的链接,然后单击后退按钮时,该index
方法只是JSON
在浏览器中打印一大串.如果我刷新,它会按预期显示HTML.这是控制器.
class RecipesController < ApplicationController
def index
@user = User.find(params[:user_id])
@recipes = Recipe.all
respond_to do |format|
format.html
format.json { render json: Recipe.where(user_id: params[:user_id]).featured }
end
end
...
end
Run Code Online (Sandbox Code Playgroud)
我尝试添加一个检查response.xhr?
,并且仅在呈现JSON
AJAX请求时才进行渲染,但这不起作用.
这是一个不使用turbolinks的Rails 3应用程序.
这是相关的Backbone代码.
# app/assets/javascripts/collections/recipe_list_.js.cofee
@App.Collections.RecipeList = Backbone.Collection.extend
url: ->
"/users/#{@userId}/recipes"
model: window.App.Models.Recipe
initialize: (opts) ->
@userId = opts.userId
# app/assets/javascripts/app.js.coffee
$ ->
urlAry = window.location.href.split('/')
userId = urlAry[urlAry.length - 2]
App = …
Run Code Online (Sandbox Code Playgroud) 看起来这是一个常见的问题,所以让我首先说我已经做了很多研究.
在这个帖子之后,我跑了
heroku labs:enable user-env-compile -a myapp
然后我确保资产通过运行在本地预编译
RAILS_ENV=production bundle exec rake assets:precompile
他们是这样.
我也遵循这个提示,设置
config.assets.initialize_on_precompile = false
在我的config/production.rb和config/application.rb中.
此外,在这个问题之后,我确保安装了heroku gem:
gem 'rails_log_stdout', github: 'heroku/rails_log_stdout'
gem 'rails3_serve_static_assets', github: 'heroku/rails3_serve_static_assets'
Run Code Online (Sandbox Code Playgroud)
然后我bin
通过遵循这篇heroku文章确保我在我的道路上.
然后我确保我遵循heroku上的"Rails 4.xx入门" 文章.
我也跟着另一个回答这个问题,放在下面的application.rb
和production.rb
config.serve_static_assets = true
Run Code Online (Sandbox Code Playgroud)
这是运行时遇到的错误git push heroku master
:
Preparing app for Rails asset pipeline
Running: rake assets:precompile
rake aborted!
could not connect to server: Connection refused
Is the server …
Run Code Online (Sandbox Code Playgroud)