javascripthtmlsqlitewinapp

how to refresh my itemlist in winapp when I insert a new data in sqlite (javascript & html)


I insert a new data into sqlite (with buttonclick) and then how to refresh my itemlist so that I can see the new data without restart the app. I use javascript&html to make a win8app.

I didn`t use databinding in the app.

 // Because we're doing the rendering, we need to put the data into the item.
        // We can't use databinding.
        result.getElementsByClassName("item-image")[0].src =currentItem.data.backgroundImage;
        result.getElementsByClassName("item-note-day")[0].textContent = currentItem.data.noteDay;
        result.getElementsByClassName("item-iconClassImage")[0].src = currentItem.data.iconImage;
        result.getElementsByClassName("item-noteTitle")[0].textContent = currentItem.data.noteTitle;
        result.getElementsByClassName("item-noteExcerpt")[0].textContent = currentItem.data.noteContent;
        return result;

What i want is when I click the button I insert my data into sqlite and the listview refresh so i can see all my datas include the new one. And I successed insert my data into sqlite.

sorry Im a Chinese, this is my first time ask question in English. I dont no am I clear or not? If anyone can help me,thank you.


Solution

  • With this SQLite component, there are two approaches. First, the simple one:

    1. use the itemDataSource provided by the component (see the unit tests for a sample)
    2. call invalidateAll on it when data changes. Either from a listener registered for insert events on the database or via application-specific events that trigger it

    The problem here is of course that it will always reload the whole list. If you want to have a dynamic list which doesn't hit the database for each update, the second approach would be to implement your own IListDataSource interface, which can become much more complicated. I did this for our app and am currently working on an abstract and reusable version of this for a pet project of mine but unfortunately I can't give any schedule on when this will be ready for a release...