DropHit
DropHit

Reputation: 1724

Nativescript observableArray with observable.fromObject - auto update view

I am challenged to understand why it is not possible to push/append items to the observable.fromObject so as to update the view. This is odd to me but im probably missing something.

I am populating this:

//declare the viewmodel
    const viewModel = new observableModule.fromObject({
    //declare the properties of this viewmodel
    bulletins: []

});

with this 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"}

It appears there is no way to add a new item using a push or set and instead it seems that the suggestion is to use the observableArray although i then lose the ability to auto-update the view :(

Upvotes: 0

Views: 203

Answers (1)

DropHit
DropHit

Reputation: 1724

It seems that the odd way to do this is to drop the observableArray into the observable.fromObject as in:

viewModel.bulletins = new ObservableArray(r);

then do a push on the array:

viewModel.bulletins.push(element); 

Maybe there is a better way?

Upvotes: 1

Related Questions