我有两个模型/存储,每个模型/存储都引用一个对象。在填充Store1并接收childId之后,填充Store2。当填充Store1时,Store2将如何收听?
Store1
for item in upList:
if item in myTable:
cell = 'B' + str(myTable.index(item))
sht.range(cell).value = "Event"
Store2(直到Store1从API调用中获得childId之前,该字段无法填充
import {action} from 'mobx'
import axios from "axios";
import {types} from "mobx-state-tree";
const Store1 = types.model('Store1', {
id: types.number,
name: types.string,
description: types.string,
childId: types.number
}).actions(self => ({
onChange(name, value) {
self[name] = value;
},
getInfo(id) {
//API call that gets uses id and returns data
self.id = data.id
self.name = data.name
self.description = data.description
self.childId = data.childId
},
}));
const store1 = Store1.create({
id: 0,
name: '',
description: '',
childId: 0
});
export default store1;
答案 0 :(得分:1)
如果Store2
依赖于Store1
,则最好在store2
实例中对其进行引用。然后,您可以简单地添加一个观察store1
实例的属性的视图,一旦观察到的属性更新,它将自动重新计算自身。