对于React Router v4中的一些嵌套路由,我有以下测试代码。
function getTreeData() {
// Get All Li elements thats contains the checkboxes form the type object,read,write
var children = $('#my_dynamic_list').children().find('li[name=children-li]');
var extracted_data = [];
for (i = 0; i < children.length ; i++) {
alert(children[i].tagName); //this gives li
if (children[i].children().find('input[name=object_ck_bx]').checked == true) { // This Line gives Uncaught TypeError: children[i].children is not a function
var profile_code = children[i].children().find('input[name=object_ck_bx]').id;
var view = children[i].children().find('input[name=view_ck_bx]').checked;
var write = children[i].children().find('input[name=write_ck_bx]').checked;
alert('profile_code' + profile_code);
var item = [];
item = { Id: profile_code, read: view, write: write };
extracted_data.push(item);
}
}
// alert(extracted_data);
return extracted_data;
}
我期望发生的事情是import React from 'react';
import { BrowserRouter as Router, Route } from 'react-router-dom';
const IndexComp = () => (
<div>
<p>IndexComp</p>
<Route exact path="/comp/inner">
<InnerComp from="child"/>
</Route>
<Route exact path="/comp/inner" render={() => (<InnerComp from="render"/>)} />
<Route exact path="/comp/inner2" render={() => (<InnerComp from="render2"/>)} />
</div>
);
const InnerComp = ({ from }) => (
<p>InnerComp from {from}</p>
);
const App = () => (
<Router>
<Route path="/comp" component={IndexComp} />
</Router>
);
export default App;
与<Route>{children}</Route>
的行为方式相同。
因此我希望'InnerComp from Child'在与'RenComp'相同的路线上呈现。
但实际上,他们没有。
这是来自React Router的<Route render={...} />
组件的预期行为吗?