-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
44 lines (36 loc) · 898 Bytes
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
function InventoryViewModel() {
var self = this;
var iconTypes = [
{
icon: "icon-bone",
text: "Bone",
},
{
icon: "icon-ball",
text: "Ball",
},
{
icon: "icon-circle",
text: "Circle",
},
{
icon: "icon-rabbit",
text: "Rabbit",
},
]; // data set
self.inventory = ko.observableArray([
]);
self.addItem = function () {
var index = Math.floor(Math.random() * iconTypes.length);
console.log(index)
self.inventory.push(iconTypes[index])
// i have a differente way to call and update the array with push()
}
self.removeItem = function (data, event) {
var indexToRemove = event.target.getAttribute("item-index");
self.inventory.splice(indexToRemove, 1)
}
};
const knockoutApp = document.querySelector("#knockout-app");
ko.applyBindings(new InventoryViewModel(), knockoutApp);
//