const MyTr = ({row}) => (
<tr>
{row.map((v, k) => <td key={k}>{v}</td>)}
</tr>
);
class MyTable extends Component {
render() {
const { data } = this.props;
return (
<Table>
{data.map((v, k) => <MyTr data={v} key={k}) />
</Table>
)
}
}
class Cupboard {
constructor(props) {
this._fromParent = { ...props };
}
delete() {
console.log(this._fromParent);
}
refreshProps(props) {
this._fromParent = { ...props }
}
//...
}
class Room {
constructor() {
this._number = 5;
this._price = 500;
this.cupboard = new Cupboard(this);
}
get number() {
return this._number;
}
set number(value) {
this._number = value;
this.cupboard.refreshProps(this);
}
}
const room = new Room();
room.cupboard.delete();
//{_number: 5, _price: 500}
room.number = 6
room.cupboard.delete()
//{_number: 6, _price: 500, cupboard: Cupboard}
const str = '<div class="abc"></div><div class="abc"></div><div class="abc"></div><div class="abc"></div><div class="abc"></div><div class="abc"></div><div class="abc"></div><div class="abc"></div><div class="abc"></div><div class="abc"></div>';
const result = str.split('</div>').reduce((prev, curr, index, arr) => {
if (index !== arr.length - 1) prev[index] = curr + '</div>';
return prev;
}, []);
// ["<div class="abc"></div>", "<div class="abc"></div>", "<div class="abc"></div>", "<div class="abc"></div>", "<div class="abc"></div>", "<div class="abc"></div>", "<div class="abc"></div>", "<div class="abc"></div>", "<div class="abc"></div>", "<div class="abc"></div>"]
var link = document.createElement('a');
link.href = 'data:text/plain;charset=UTF-8,' + encodeURIComponent(yourTextGoesHere);
link.download = 'some file name.txt';
link.click();
var masterArray = ['1981', '2001,2002', '1991', '1985,1986,1987'];
let result = [];
compareArray.forEach((v, k) => {
let i = 0;
masterArray[k].split(',').forEach((vv, kk) => {
v.split(',').indexOf(vv) !== -1 ? i++ : false
});
result.push(`${k} - [${i}]`)
});
console.log(result);
const getList = (data) => {
let res = [];
const toList = ({serve, name, children}, index, prefix = '') => {
const id = prefix ? prefix + '.' + (index + 1) : (index + 1);
res.push({id: id, serve: serve, name: name});
children && children.length > 0 && children.forEach((v, k) => toList(v, k, id));
}
data.forEach((item, key) => {toList(item, key)});
return res;
}