Что лучший способ состоит в том, чтобы сохранить несколько значений за $ jQuery .data ()?

Позвоните parent::__construct() в a::__construct():

class a extends b
{
   public function __construct()
   {
       parent::__construct();
   }   

   public function validateStuff()
   {
      $this->insert_record();
   }
}

. Вы можете вообще не указывать конструктор a, если вы не делаете какой-то специфической вещи.

11
задан Brian Tompsett - 汤莱恩 7 November 2015 в 16:51
поделиться

2 ответа

If both approaches are as easy to use in your code, go for storing a single object. It avoids the extra overhead of calling the data() method every time you need a value. This way, you can fetch the mapping object with one call to data(), and then retrieve values from this object as many times as you want without having to call data() again.

The data() method uses objects to map elements to keys/values under the hood, so it does not offer any performance improvements over managing a mapping object yourself.

6
ответ дан 3 December 2019 в 06:22
поделиться

Я бы, вероятно, сделал что-то вроде:

var data = $("#div_id").data();   
data.foo=1;  
data.bar=2;
3
ответ дан 3 December 2019 в 06:22
поделиться
Другие вопросы по тегам:

Похожие вопросы: