开发者

Array of data on js - is it good?

开发者 https://www.devze.com 2023-04-04 18:25 出处:网络
Is it good to organize array of data开发者_Go百科 in js file? I have about 70 strings of data like (price sheet with id): 1,\'LF5W13ZE0\',\'289,19\'

Is it good to organize array of data开发者_Go百科 in js file? I have about 70 strings of data like (price sheet with id): 1,'LF5W13ZE0','289,19'

2,'BP0118110BKR5E11NGK','174,19'

And i want to load from it to html (using JQuery)? Using myArray[0] =.

Is it rational to load this big file via client? or better use PHP (server side)?


If you'd like to keep one place containing all products, you may use an external .js file.

A possible format for that external js file:

var products = [];
// auto-generated below, use other array indices if needed
products[0] = ['LF5W13ZE0', '289,19'];
products[1] = ['BP0118110BKR5E11NGK', '174,19'];

You can also use object literals like {id: 'LF5W13ZE0', price:'289,19'}, but the idea remains the same.

Another points to consider is whether the inclusion of the product details in a separate js file is worth the effort. You may run in issues if the js file was cached for example and need some way to insert the values from JS in the HTML.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号