我在 django 1.8 中使用 django-autocomplete-light。它有时会失败。这是 javascript 控制台错误:
TypeError: $(...).select2 is not a function
;(function ($) {
$(document).on('autocompleteLightInitialize', '[data-autocomplete-light-function=select2]', function() {
var element = $(this);
// This widget has a clear button
$(this).find('option[value=""]').remove();
$(this).select2({
Run Code Online (Sandbox Code Playgroud)
昨天它运行良好,没有任何改变,但今天它不起作用。我也在使用 django 套装。我觉得我的 django 应用程序之间存在 javascript 不兼容导致这种随机行为,但我不知道如何追查原因。有任何想法吗?
这是我的所有代码:
# models.py
class Sample(models.Model):
name = models.CharField(max_length=200)
def __unicode__(self):
return self.name
class Doctor(models.Model):
name = models.CharField(max_length=200)
address = models.CharField(max_length=200, null=True, blank=True, default='')
def __unicode__(self):
return self.name
class Patient(models.Model):
name = models.CharField(max_length=200)
sample = models.OneToOneField(Sample, null=True, blank=True)
doctor = models.ForeignKey(Doctor, …Run Code Online (Sandbox Code Playgroud)