Reason 原因组件中未绑定的记录字段名称
借用Yawar的所有有用信息,我有以下几点:Reason 原因组件中未绑定的记录字段名称,reason,reason-react,Reason,Reason React,借用Yawar的所有有用信息,我有以下几点: $cat src/index.re let products = [| {name: "Football", price: 49.99}, {name: "Basebll", price: 1.99}, {name: "Poker", price: 33.99} |]; ReactDOMRe.renderToElementWithId( <ProductTable products /> ); $cat src/
$cat src/index.re
let products = [|
{name: "Football", price: 49.99},
{name: "Basebll", price: 1.99},
{name: "Poker", price: 33.99}
|];
ReactDOMRe.renderToElementWithId(
<ProductTable products />
);
$cat src/productRow.re
let component = ReasonReact.statelessComponent("ProductRow");
let echo = ReasonReact.stringToElement;
let make = (~name: string, ~price: float, _) => {
...component,
render: (_) => {
<tr>
<td>{echo(name)}</td>
<td>{price |> string_of_float |> echo}</td>
</tr>
}
};
$cat src/ProductTable.re
let component = ReasonReact.statelessComponent("ProductTable");
let echo = ReasonReact.stringToElement;
let make = (~products, _) => {
...component,
render: (_) => {
let productRows = products
|> Array.map(({name, price}) => <ProductRow key=name name price />)
|> ReasonReact.arrayToElement;
<table>
<thead>
<tr>
<th>{echo("Name")}</th>
<th>{echo("Price")}</th>
</tr>
</thead>
<tbody>productRows</tbody>
</table>
}
}
$cat src/index.re
让产品=[|
{名称:“足球”,价格:49.99},
{名称:“Basebll”,价格:1.99},
{名称:“扑克”,价格:33.99}
|];
ReactDOMRe.renderToElementWithId(
);
$cat src/productRow.re
让component=ReasonReact.statelementComponent(“ProductRow”);
让echo=ReasonReact.stringToElement;
让make=(~name:string,~price:float,))=>{
组成部分
渲染:())=>{
{echo(名称)}
{price |>string_of_float |>echo}
}
};
$cat src/ProductTable.re
让component=ReasonReact.statelementComponent(“ProductTable”);
让echo=ReasonReact.stringToElement;
让make=(~products,)=>{
组成部分
渲染:())=>{
让productRows=产品
|>map(({name,price})=>)
|>ReasonReact.array元素;
{echo(“Name”)}
{echo(“价格”)}
productRows
}
}
我得到以下编译时错误:
7 ┆ render: (_) => {
8 ┆ let productRows = products
9 ┆ |> Array.map(({name, price}) => <ProductRow key=name name price />
)
10 ┆ |> ReasonReact.arrayToElement;
11 ┆
Unbound record field name
7┆ 渲染:())=>{
8.┆ 让productRows=产品
9┆ |> Array.map(({name,price})=>
)
10┆ |> ReasonReact.array元素;
11┆
未绑定记录字段名
如何修复此编译时错误?编译器将为您推断许多类型的原因,但对于记录,您必须首先声明它有哪些字段(及其类型) 根据@yawar的有用答案,您只需在文件顶部包含类型定义:
type product={name:string,price:float};
有了这一点,编译器将能够分辨出
产品
属于数组(产品)
类型,并且应该从那里愉快地继续下去。试试看编译器将为您推断出许多类型,但对于记录,您必须首先声明它有哪些字段(及其类型)
根据@yawar的有用答案,您只需在文件顶部包含类型定义:
type product={name:string,price:float};
这样,编译器就可以判断products
属于array(product)
类型,并且应该从那里开始愉快地继续。试试看