Using Ionic Framework, how do you refresh from localstorage? - javascript

I have a problem with refreshing from localStorage.
I have list of items. I can display them. I add one item to array and display.
Everything works fine. I can display. I can see that another object was
added to items array.
When I close and reopen app. The alert shows object exists and has correct number of items. Only problem is I dont see the items now in the view.
Is this $scope problem or async problem. The array exists..
Edit:
I have array with three items. I push to localstorage, first.
then use data from localstorage to bring into '$scope.items'.
In the view, the data is shown from '$scope.items'. Everything
works as expected. I turn off app turn back on, And the array
loads properly from localstorage. This is not a problem.
Now, the view has ability to add to array. I can add to array,
Again loading from localstorage. There is an alert, which shows
that the array has one more object. I can add another item and .....
All of them show up in the view. All updates come from localstorage.
I turn app on and off, there is nothing in the view. This is done
on a phone so I cant check localstorage.

You did not post any code so I will just do my best to help. are you fetching items from local storage and setting to to a $scope variable? also fetching the item from local storage on app load and put it in a service or do it before the view that needs the data enters the view.
like this:
$scope.$on('$ionicView.beforeEnter', function () {
$scope.items = localStorage.getItem('youritem');
});

This solved the problem. It was a ng-repeat issue.
<div ng-repeat="row in [1,1,1] track by $index">

Related

angular page data sort itself when click anywhere on page

Mouse Click anywhere on the page, even blank spot, the data array on the page just resort itself.
I know that click might trigger view change if impure pipe is set but I didn't use any.
So I am really baffled because my development testing is OK. Only the production build has this weird behavior.
I use angular 8. The data on the page is array down from rest endpoint. I simply for loop it like all other pages does. This page is just having a big object as the response and containing 3 big arrays. And I make 3 different list on the page. Each list is also a input for a sub component. Display after sorting.
I know JS sort does not copy. But why only on production build?
I fixed it by removing the pipe which is used to filter the lists. That's it.
But I couldn't explain the cause of it.
The pipe is doing a filter. It filters the list based on some ids which belongs to the data.
A checkbox will trigger the filtering which is *ngIf on the tables row in the template.

retrieving single object from json in react

I have searched far and wide, I have a long history with Angular and am sorta new to the world of React. I am looking to retrieve a single item at a time from my json file. The data is synced and it loops into render flawlessly. This would be .map(), however I do not wish to display all items in the json at once. I would like to show 1 item, then click through with navigation I have set up to show each one individually. In Angular this is done by doing something like this data[0].item index item displays.
Any ideas? Thank You

Store and load JavaScript variables via Json

I need to store some dynamic variables in a Json file (i was told this would work) to be able to load them in multiple pages. Per example a customer should be able to select one thing in one page (a highlighted div) and then go to another page, select some items there and be able to go pack to the other page and that div is still selected. (Variables remembered) Now i tried to google and search here but found nothing matching my description. Please help me!
Try using localstorage, store selected values by user in localstorage and check this at page ready or load if it exists in loacalstorage show that value or div with highlight as per your functionality and if localstorage doesn't had a value then consider it as first time user come to this page.
but be careful using localstorage as you have to clear it when you done with it, it may cause memory leakage problem.

About Angular list

I want to create a list using Angular, where the data (say like over 1000 items) is retrieved from the server using JSON call. In my plan, the list will only show x amount of items in the list, and will load x more items into it when the user pull up the list.
So my question here is, how to write the expression for the ng-repeat so that
It will only show x amount of items when first loading the list
It will only load x amount of items when user pulled up the list
I think i read somewhere about ngRepeat being able to do this kind of feature, to limit and control the amount of items shown or loaded onto the list, but i forgot where i read it.
But someone told me that better way of doing this is by limiting the amount of data retrieved when using JSON call rather than letting Angular do it.
So i'm kind of confuse in here.
Take a look at ngInfiniteScroll http://binarymuse.github.io/ngInfiniteScroll/.
Last fall, i want to use a similar solution and ended up there.

Refreshing Only Favorites using Javascript

I have a Data Extender in place that modifies the Favorites' titles when ever favorites are requested. But when I add a single favourite, only that item is updated without calling the whole list. My question is how do I refresh only the favorites part in Tridion using JavaScript so that the entire favorites list is retrieved and the list is run through my data extender so that the title is updated.
So How do I refresh favorites only in Tridion using JavaScript?
$models.$cme.getShortcuts().getList().unload()
I don't have an instance open to test with, but in the PowerTools AddUser tool I refresh the main list using:
$display.getView().refreshList();
I imagine you can pass a view name to the function to specify which view you want to refresh.
The source for the tool command is at
http://code.google.com/p/tridion-2011-power-tools/source/browse/trunk/PowerTools.Editor/PowerTools/Client/AddUser/AddUserCommand.js

Categories