我一直在我的spec文件中重复一些注入模板然后编译它的代码.我将这段代码提取到一个辅助函数中,以保持干燥.我认为问题在于试图将其置于beforeEach
辅助函数中.这是我试图抽象成函数的代码片段:
beforeEach(module('app/views/header.html'));
beforeEach(inject(function($templateCache, $compile, $rootScope) {
template = $templateCache.get('app/views/header.html');
$templateCache.put('views/header.html', template);
var directive = angular.element('<clinical-header></clinical-header>');
element = $compile(directive)($rootScope);
$rootScope.$digest();
}));
Run Code Online (Sandbox Code Playgroud)
这是我创建的辅助函数:
var setupTemplate = function(templateName, element) {
beforeEach(module('app/views/' + templateName));
beforeEach(inject(function($templateCache, $compile, $rootScope) {
var template = $templateCache.get('app/views/' + templateName);
$templateCache.put('views/' + templateName, template);
var directive = angular.element(element);
element = $compile(directive)($rootScope);
$rootScope.$digest();
}));
Run Code Online (Sandbox Code Playgroud)
现在这是对辅助函数的调用:
setupTemplate('header.html', '<clinical-header></clinical-header>');
Run Code Online (Sandbox Code Playgroud)
在我的辅助函数结束时,一切看起来都不错,但是当我跳到我的it
块时,一切都是未定义的.我可以提取多个beforeEach
?这样做的正确方法是什么?另外,放置茉莉花辅助功能的适当位置在哪里?如何完成?
我有一个函数,用于映射数组underscore
.这是功能:
var services = _.map(userCopy.get('services'), function (service) {
if (service.service_selected === true) {
return service;
}
});
Run Code Online (Sandbox Code Playgroud)
我的问题是,当conditional === false
我,然后我被undefined
投入services
.当然我可以删除undefined
,但这很难看,我只是想map
正确使用.我该如何解决?
我试图点击甚至与表格一起工作reactjs
.我的第一次尝试是使整行可以点击.这是我的代码:
var UserList = React.createClass({
getInitialState: function() {
return getUsers();
},
handleClick: function(e) {
console.log("clicked");
},
render: function() {
var users = this.state.users.map(function(user) {
return (
<tr onClick={this.handleClick}>
<td>{user.name}</td>
<td>{user.age}</td>
<td></td>
</tr>
);
});
return(
<div className="container">
<table className="table table-striped">
<thead>
<tr>
<th>Name</th>
<th>Age</th>
<th>Full Detail</th>
</tr>
</thead>
<tbody>
{users}
</tbody>
</table>
</div>
);
}
});
Run Code Online (Sandbox Code Playgroud)
这没用.然后我尝试在表格中添加一个按钮:
<button className="btn" onClick={this.handleClick}>Full Detail</button>
Run Code Online (Sandbox Code Playgroud)
这也行不通.我有其他onClick
人在我的应用程序中工作,但我如何使用表格来完成这项工作?
有没有办法将a传递templateUrl
给我的指令.我知道我可以使用翻译,但这似乎太多了.例如,我有一个widget
指令,我想填写特定的HTML.有没有办法传递它像:
<div widget templateUrl="template1.html"></div>
<div widget templateUrl="template2.html"></div>
Run Code Online (Sandbox Code Playgroud) 我在Rails中创建一个REST服务.这是我的路线.
resources :users
match '/users', :controller => 'users', :action => 'options', :constraints => {:method => 'OPTIONS'}
Run Code Online (Sandbox Code Playgroud)
我能够[获取]我的用户.我正在尝试更新我的用户,但我收到错误消息:
ActionController::RoutingError (No route matches [OPTIONS] "/users/1"):
Run Code Online (Sandbox Code Playgroud)
当我在rake routes
这里跑的是我给的路线:
users GET /users(.:format) users#index
POST /users(.:format) users#create
new_user GET /users/new(.:format) users#new
edit_user GET /users/:id/edit(.:format) users#edit
user GET /users/:id(.:format) users#show
PUT /users/:id(.:format) users#update
DELETE /users/:id(.:format) users#destroy
/users(.:format) users#options {:method=>"OPTIONS"}
Run Code Online (Sandbox Code Playgroud)
有人可以告诉我如何修复我的路线,以便我可以进行任何类型的REST呼叫吗?谢谢.
我正在建立一个Backbone
项目,Handlebars
我遇到了一个Handlebars
没有找到编译方法的问题.这是我的配置文件:
require.config({
hbs: {
templateExtension: '.hbs'
},
paths: {
backbone: "libs/backbone/backbone",
handlebars: 'libs/handlebars/handlebars.amd',
hbs: 'libs/requirejs-hbs/hbs',
jquery: 'libs/jquery/jquery',
jqueryMockAjax: 'libs/jquery-mockjax/jquery.mockjax',
text: 'libs/requirejs-text/text',
templates: 'templates/',
underscore: 'libs/underscore/underscore'
},
shim: {
backbone: {
deps: [
'underscore',
'jquery'
],
exports: 'Backbone'
},
hbs: {
deps: ['handlebars'],
exports: 'hbs'
},
jqueryMockAjax: {
deps: [ 'jquery' ],
exports: '$.mockjax'
},
underscore: {
exports: '_'
}
}
});
require(['app'], function(App) {
'use strict';
var app = new App();
app.render();
});
Run Code Online (Sandbox Code Playgroud)
这是 …
我正在尝试Promise.all
使用一系列项目创建一个.所以,如果我像这样创建它,它工作正常
Promise.all([
Query.getStuff(items[0]),
Query.getStuff(items[1])
]).then(result => console.log(result))
Run Code Online (Sandbox Code Playgroud)
如果我尝试创建Promise.all
这样的,它不起作用
Promise.all([
items.map(item => Query.getStuff(item))
]).then(result => console.log(result))
Run Code Online (Sandbox Code Playgroud)
该then
块在之前运行Query.getStuff(item)
.我错过了什么?
今天早上我看了Railscast 328,我很难找到一个方法的文档.
<%= link_to t('.edit', :default => t("helpers.links.edit")),
edit_boy_scout_path(boy_scout), :class => 'btn btn-mini' %>
Run Code Online (Sandbox Code Playgroud)
我理解link_to方法,但我对t('edit ....)参数感到困惑,它在这个方法中调用了两次.解释甚至指向一些文档都会很棒.谢谢你的帮助
我正在设置REST
服务,我正在使用它postgres
作为数据存储.我想知道如何设置postgres
查询以使用可选参数.即:
SELECT * from users
where hair_color = $1
and eye_color = $2
Run Code Online (Sandbox Code Playgroud)
$ 1和$ 2来自请求:[req.body.hair_color,req.body.eye_color]
如果用户没有通过该怎么办?eye_color
在这种情况下,我想要所有的眼睛颜色.我假设我不必if/else
在这里做一堆陈述.创建此查询的简洁方法是什么?
我正在看redux-blog-example.有SignupRoute.js
它看起来像这样:
@connect(state => ({
auth: state.auth
}), {
signup
})
export default class SignupRoute extends React.Component {
static contextTypes = {
router: React.PropTypes.object
}
handleSubmit = (email, password) => {
const router = this.context.router;
this.props.signup(email, password, router);
}
render() {
return (
<Signup
auth={this.props}
handleSubmit={this.handleSubmit}
/>
);
}
}
Run Code Online (Sandbox Code Playgroud)
如何router
连接到context
这个class
?
javascript ×5
angularjs ×2
reactjs ×2
activerecord ×1
arrays ×1
backbone.js ×1
jasmine ×1
karma-runner ×1
postgresql ×1
promise ×1
requirejs ×1
rest ×1
routes ×1
ruby ×1