Answered by:
regarding HTML5/Javascript

Question
-
hi,
I am working on metro ui from past 1 month.i have 2 questions to ask
1)how to add data dynamically in JavaScript. I have found code for c# but I need it for JavaScript.
2)how to add bookmarks to a news application.
Tuesday, August 7, 2012 10:14 AM
Answers
-
Hi
For your first question:
You can use WinJS.Binding.List object to store your data.
Then use WinJS.Binding.as to bind the Data to a Winjs.Namespace.
For example:
//define the data namespace. (function () { "use strict"; var shoppingItemsList = new WinJS.Binding.List(); var preferredStoresList = new WinJS.Binding.List(); WinJS.Namespace.define("ViewModel", { UserData: WinJS.Binding.as({ homeZipCode: null, getStores: function () { return preferredStoresList; }, addItem: function (newName, newQuantity, newStore) { shoppingItemsList.push({ item: newName, quantity: newQuantity, store: newStore }); } }) }); // statements to add test data removed for brevity })();
//add data to the namespace ViewModel.UserData.addItem("Ice Cream", 1, "Vanilla", "Walmart");
The WinJS.Binding.as method replaces data properties with getters and setters that trigger
notifications when the property value change.For the second:
Can you explain it clearer?
- Marked as answer by Sareddy Kalpana Thursday, August 9, 2012 7:50 AM
Tuesday, August 7, 2012 4:52 PM -
No you would have to design and implement what you think bookmarks should look like and how they would behave in your application. There is no generic concept of bookmarks.
-Jeff
Jeff Sanders (MSFT)
- Marked as answer by Sareddy Kalpana Friday, August 10, 2012 9:24 AM
Thursday, August 9, 2012 5:26 PMModerator
All replies
-
Hi
For your first question:
You can use WinJS.Binding.List object to store your data.
Then use WinJS.Binding.as to bind the Data to a Winjs.Namespace.
For example:
//define the data namespace. (function () { "use strict"; var shoppingItemsList = new WinJS.Binding.List(); var preferredStoresList = new WinJS.Binding.List(); WinJS.Namespace.define("ViewModel", { UserData: WinJS.Binding.as({ homeZipCode: null, getStores: function () { return preferredStoresList; }, addItem: function (newName, newQuantity, newStore) { shoppingItemsList.push({ item: newName, quantity: newQuantity, store: newStore }); } }) }); // statements to add test data removed for brevity })();
//add data to the namespace ViewModel.UserData.addItem("Ice Cream", 1, "Vanilla", "Walmart");
The WinJS.Binding.as method replaces data properties with getters and setters that trigger
notifications when the property value change.For the second:
Can you explain it clearer?
- Marked as answer by Sareddy Kalpana Thursday, August 9, 2012 7:50 AM
Tuesday, August 7, 2012 4:52 PM -
thanks for your answer. and the second one is regarding adding bookmarks that means if we have to save a link we have favorites bar in the same way we have bookmarks bar also.
http://msdn.microsoft.com/en-us/library/windows/apps/hh868272.aspx
in the above link I have found an example regarding news app in that it has adding bookmarks concept but I didn't find any code to add bookmarks.
and I have one more question
can we store data using database? In some sites I have read that it is not possible but in some it is written that by using SQLite it is possible. can u give me the exact answer?
Wednesday, August 8, 2012 9:26 AM -
There is no built in support for bookmarks. You must design and implement this. You can use SQLight, a web based data storage or indexeddb in your application.
Jeff Sanders (MSFT)
- Proposed as answer by Jeff SandersMicrosoft employee, Moderator Wednesday, August 8, 2012 12:36 PM
Wednesday, August 8, 2012 12:36 PMModerator -
thanks for your answer. could u please say how to implement bookmarks?Thursday, August 9, 2012 7:53 AM
-
No you would have to design and implement what you think bookmarks should look like and how they would behave in your application. There is no generic concept of bookmarks.
-Jeff
Jeff Sanders (MSFT)
- Marked as answer by Sareddy Kalpana Friday, August 10, 2012 9:24 AM
Thursday, August 9, 2012 5:26 PMModerator -
ok thanks for your valuable answers.Friday, August 10, 2012 9:25 AM