我正在尝试asMap
并希望输出与coverType
匹配的图书标题:
以下是BookStore
:
class BookStore {
@observable coverType = 'soft';
@observable booksByIdMap = asMap({
"88cd7621": {
"id": "88cd7621",
"title": "The Secret",
"coverType": 'soft'
},
"88cd7622": {
"id": "88cd7622",
"title": "The Alchemist",
"coverType": 'hard'
},
"88cd7623": {
"id": "88cd7623",
"title": "Javascript",
"coverType": 'soft'
}
});
@computed get byCoverType() {
return this.booksByIdMap.filter(book => book.coverType == this.coverType);
}
}
以下是用户界面:
const bookStore = new BookStore();
const BookViewItem = observer(({book}) =>
<li>
{book.title}
</li>
);
@observer
class BookView extends Component {
render() {
return <div>
<h1>Books With Cover Type: {bookStore.coverType}</h1>
<ul>
{bookStore.byCoverType().map(book =>
<BookViewItem book={book} key={book.id} />
)}
</ul>
</div>
}
}
但它不会根据当前coverType
值呈现图书标题。
这是一个小提琴: https://jsfiddle.net/ob7v1gk5/
如何使用计算出的Bookstore.byCoverType
过滤结果输出图书标题?
答案 0 :(得分:1)
MobX映射不是数组,因此它没有过滤器和其他特定于阵列的方法。查看documentation to see what methods you can use。
你可以,例如使用xAxis: {
type: 'datetime',
tickPixelInterval: 60, //spacing xaxis labels
min: startTime, //Today, 00h in TS
max: endTime //Today, 23h59 in TS
},
series: [
{ name:"test",
data:[[1482911520000,10],
[1482911620000,11],
[1482911720000,12],
[1482911820000,13],
[1482911920000,14]]
}]
方法,然后在生成的数组like this上使用values
:
filter