0

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.

rick
  • 3
  • 2
  • Which SQLite component do you use? Since you're not using databinding I suppose that you're also not using a WinJS.UI.ListView? Anyway, I can _really_ recommend using databinding. – Marcus Ilgner May 15 '13 at 09:01
  • I use WinJS.UI.ListView. Because I need my datas display in listview with different size, so I can`t use databingding. If I use databingding I can`t set my datas in different size I want. this is a sample from msdn. well, If I use databinding how to refresh it? thank you. @ma_il – rick May 15 '13 at 09:32
  • You can still use databinding and display different-sized items. See http://msdn.microsoft.com/en-us/library/windows/apps/jj585523.aspx for that. Anyway, which SQLite component do you use? – Marcus Ilgner May 15 '13 at 09:53
  • Ok I will try,thank you. about sqlite here is what I use https://github.com/doo/SQLite3-WinRT @ma_il – rick May 15 '13 at 10:07

1 Answers1

0

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...

Marcus Ilgner
  • 6,935
  • 2
  • 30
  • 44