我很难理解为什么不能通过向observable.fromObject推送/追加项目来更新视图。这对我来说很奇怪,但我可能遗漏了一些东西。
我正在填充以下内容:
//declare the viewmodel
const viewModel = new observableModule.fromObject({
//declare the properties of this viewmodel
bulletins: []
});使用这个json:
{"total_bulls":"664","GenericName":"Tocilizumab","brandName":"Actemra","drugCat":"(IL-6) Receptor Antagonist","bullID":4847,"fastURL":"https:\/\/gotopills.com\/?post_type=drug-bulletin&p=4847","litAlertLvl":"High"}似乎没有办法使用推送或设置来添加新项目,相反,建议使用observableArray,尽管这样我就失去了自动更新视图的能力:(
发布于 2019-08-22 15:02:43
执行此操作的奇怪方法似乎是将observableArray放入observable.fromObject,如下所示:
viewModel.bulletins = new ObservableArray(r);然后在数组上执行推送:
viewModel.bulletins.push(element); 也许有更好的方法?
https://stackoverflow.com/questions/57603720
复制相似问题