简体   繁体   English

映射时嵌套数据表

[英]Nested datatable while mapping

Basically I have two tables products and categories . 基本上我有两个表的productscategories I managed to map out products with: 我设法通过以下方式映射products

var ProductsList = React.createClass({
render: function () {
    var EachProduct = this.props.data.map(function (item) {
        return (
                <SingleProduct key={item.Id } data={item}/>
        );
    });
    return (
        <ul>
            {EachProduct}
        </ul>
        );
}

}); });

...and there is yet that second table categories . ...还有第二种表categories I tried googling but I did not really knew how to google it. 我尝试了谷歌搜索,但我真的不知道如何用谷歌搜索。 Normally I could just send two models to view from controller and could just do foreach in foreach and the second one would just look into categories for fk_product_id or something like that, so that <SingleProduct/> class could show all categories that are connected with mapped product ..but this is just a different story. 通常,我可以发送两个模型以从控制器进行查看,并且可以在foreach中执行foreach,而第二个模型将仅查看fk_product_id categories或类似内容,以便<SingleProduct/>类可以显示与已映射关联的所有类别产品..但这只是一个不同的故事。

How to do that? 怎么做?

Maybe something like this would help: 也许这样会有所帮助:

render: function () {
var EachProduct = this.props.data.map(function (item) {
    var category = this.props.categories.find((categoryItem)=>{
         return (item.categoryId === categoryItem.id)
    })
    return (
            <SingleProduct key={item.Id } data={item} category={category}/>
    );
});
return (
    <ul>
        {EachProduct}
    </ul>
    );

} }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM