我期待创建一个无状态组件,其输入可以由父元素验证.
在下面的示例中,我遇到了一个问题,即输入引用永远不会被分配给父的私有input属性.
什么时候ref叫,_emailAddress是handleSubmit.有什么我想念的,还是有更好的方法来做到这一点?
interface FormTestState {
errors: string;
}
class FormTest extends React.Component<void, FormTestState> {
componentWillMount() {
this.setState({ errors: '' });
}
render(): JSX.Element {
return (
<main role='main' className='about_us'>
<form onSubmit={this._handleSubmit.bind(this)}>
<TextInput
label='email'
inputName='txtInput'
ariaLabel='email'
validation={this.state.errors}
ref={r => this._emailAddress = r}
/>
<button type='submit'>submit</button>
</form>
</main>
);
}
private _emailAddress: HTMLInputElement;
private _handleSubmit(event: Event): void {
event.preventDefault();
// this._emailAddress is undefined
if (!Validators.isEmail(this._emailAddress.value)) {
this.setState({ errors: 'Please enter an email address.' …Run Code Online (Sandbox Code Playgroud) 我的Rails应用程序有一个完美的播放器类.可以从我的rails控制面板创建,删除和更新播放器,而不会出现任何问题.
我希望远程对手能够通过使用JSON请求创建玩家来加入乐趣.遵循我的create方法上面自动生成的Rails注释的建议:# POST /players.json我已经开始发送请求了localhost:3000/players.json
JSON
{
"player": {
"name": "test",
"room_id": 0,
"skin_id": 1,
"head_id": 2,
"torso_id": 3,
"legs_id": 4,
"x_position": 5,
"y_position": 6,
"direction": 7,
"action": "",
"gender": "f"
}
}
Run Code Online (Sandbox Code Playgroud)
但是,我遇到此错误消息:
ActionController::ParameterMissing in PlayersController#create
param not found: player
所以我想我的问题是:我应该如何构建我发送的JSON?
附加信息:
更新 - 玩家参数
这是我的控制器中的玩家参数方法(根据要求):
def player_params
params.require(:player).permit(:name, :room_id, :skin_id, :head_id, :torso_id, :legs_id, :x_position, :y_position, :direction, :action, :gender)
end
Run Code Online (Sandbox Code Playgroud)
更新2 - 播放器控制器
class PlayersController < ApplicationController
before_action :set_player, only: [:show, …Run Code Online (Sandbox Code Playgroud) 当尝试从模型执行我的数据库上下文中的.Where()时,我遇到以下错误消息:
System.Data.Entity<RPSManagementSystem.Model.StoreUser> does not contain a definition for Where...
Run Code Online (Sandbox Code Playgroud)
这在从控制器调用时有效.是什么赋予了?
从模型:
[NotMapped]
private List<StoreUser> _stores { get; set; }
[NotMapped]
public List<StoreUser> Stores
{
get
{
if (this._stores == null || this._stores.Count <= 0)
{
using (RPSEntities db = new RPSEntities())
{
this._stores = db.StoreUsers.Where(su => su.Username == this.Username);
}
}
return _stores;
}
}
Run Code Online (Sandbox Code Playgroud)
为了确保我没有疯狂,我将它粘贴到我的控制器中 - 它看起来在起作用.屏幕截图如下:
在模型中:

在控制器中:

我在Typescript中有一个抽象基类,如下所示:
import {Http, Headers, Response} from 'angular2/http';
export abstract class SomeService {
constructor(private http:Http) {}
protected post(path:string, data:Object) {
let stringifiedData = JSON.stringify(data);
let headers = new Headers();
headers.append('Content-Type', 'application/json');
headers.append('Accept', 'application/json');
this.http.post(`http://api.example.com/${path}`, stringifiedData, { headers })
.map(res => res.json())
.subscribe(obj => console.log(obj));
}
}
Run Code Online (Sandbox Code Playgroud)
它完美地运作.但是,Typescript编译器正在抱怨.map(res => res.json()).我一直收到这个错误:
ERROR in ./src/app/components/shared/something/some.abstract.service.ts
(13,29): error TS2339: Property 'json' does not exist on type '{}'.
Run Code Online (Sandbox Code Playgroud)
我按照角度2文档中的示例进行操作,它可以工作.我只是厌倦了盯着这个错误.我错过了什么吗?
我a,在表单中构建一个下拉菜单,以这种形式显示可用选项及其价格的列表:"service - price".然而,我的问题是它看起来不像我可以在我的控制器中使用number_to_currency.有没有其他方法可以实现相同的效果,或从我的控制器访问number_to_currency?这是我最初的努力:
@levels = []
DistributorLevel.all.each do |d|
price = (d.price > 0) ? number_to_currency(d.price) : "Free"
@levels << ["#{d.name} - #{price}", d.id]
end
Run Code Online (Sandbox Code Playgroud) 我试图使用这里描述的订阅功能.但是,在编辑时/assets/js/app.js,我收到此错误:
Uncaught ReferenceError: Room is not defined
Run Code Online (Sandbox Code Playgroud)
所以,我不完全确定为什么,但它找不到我的模型.这是我的代码:
Room.subscribe(req, [{id: "5278861ab9a0d2cd0e000001"}], function (response) {
console.log('subscribed?');
console.log(response);
});
Run Code Online (Sandbox Code Playgroud)
这是在app.js的上下文中
(function (io) {
// as soon as this file is loaded, connect automatically,
var socket = io.connect();
if (typeof console !== 'undefined') {
log('Connecting to Sails.js...');
}
socket.on('connect', function socketConnected() {
// Listen for Comet messages from Sails
socket.on('message', function messageReceived(message) {
///////////////////////////////////////////////////////////
// Replace the following with your own custom logic
// to run when a new …Run Code Online (Sandbox Code Playgroud) 在测试/推送到生产时不断更改我的web.config文件变旧,所以当我不更改文件时,必须记住从我的暂存更改中删除它.
我尝试使用Sourcetree中的"停止跟踪"选项(我认为将该文件添加到我的GitIgnore),但看起来它会从我的远程仓库中删除该文件.
是否可以将文件保留在我的远程仓库中,并停止跟踪本地更改?
我即将开始一个Web应用程序,我想使用实体框架(主要是)代码优先模型.
但是,除了我计划创建的特定于应用程序的模型之外,我还必须使用外部用户数据库.是否可以首先将我的一个模型指定为数据库并使用单独的数据库上下文?
我试图使用JSON.Net加载本地存储在ASP.Net MVC 4站点上的JSON文件,但是我无法指向该文件.这是我想要做的:
List<Treatment> treatments = JsonConvert.DeserializeObject<List<Treatment>>(Server.MapPath("~/Content/treatments.json"));
Run Code Online (Sandbox Code Playgroud)
并且我遇到了这个错误:
An exception of type 'Newtonsoft.Json.JsonReaderException' occurred in Newtonsoft.Json.dll but was not handled in user code
Additional information: Unexpected character encountered while parsing value: c. Path '', line 0, position 0.
Run Code Online (Sandbox Code Playgroud)
我应该做些什么呢?
我一直遇到这个错误:
CsvHelper.dll中发生未处理的"CsvHelper.CsvReaderException"类型异常
附加信息:没有为"RPS_String_Parse.Program + FormattedRow"类型映射属性.
但我相信我正确地遵循了文档.在引用"入门"部分之后我实现了这个:
using (var sr = new StreamReader(filePath))
{
var csv = new CsvReader(sr);
var records = csv.GetRecords<FormattedRow>();
foreach (var record in records)
{
Console.WriteLine(record.Address1);
}
Console.ReadLine();
}
Run Code Online (Sandbox Code Playgroud)
和我的班级:
public class FormattedRow
{
public string IDOrderAlpha;
public string IDOrder;
public string AddressCompany;
public string Address1;
public string Address2;
public string AddressCity;
public string AddressState;
public string AddressZip;
public string AddressCountry;
public string ShipMethod;
public string ContactEmail;
public string ContactName;
public string ServiceRep;
public string …Run Code Online (Sandbox Code Playgroud)