Storing data in the DOM

前端 未结 3 1843
名媛妹妹
名媛妹妹 2021-01-13 11:32

I have a list of books and I want to store data against each book e.g. Price, Quantity, id, catergory id, size, weight etc.

I was looking at storing all this in the

3条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-13 11:43

    The data- attributes are generally used more as a way to get data into your JavaScript (i.e. From your server-side template), and less a runtime place to store your data. A better place keep your active data is in a JavaScript object, especially if you will be accessing it or manipulating it frequently during the life of your script.

    This is more in keeping with an MVC approach, where the data lives in your Model, but may be represented in your View. For this reason, some of the newer MVC frameworks like AngularJS provide automatic two-way binding between the two.

提交回复
热议问题