所以,我一直在研究一个django项目(使用djagno 1.11),我看到一个非常酷的聊天功能,有人嘲笑(使用django 2.0)here和他们的git repo here 。我可以在自己的应用程序中按照指南重新创建整个项目,但是当我将它添加到我自己的应用程序时,我遇到了麻烦。我当前的应用程序使用bootstrap并有javascript将项目添加到购物车和其他类似的东西,我想知道这是否妨碍了。其他的JavaScript仍然有效,新的JavaScript不会'。我收到了你的基本错误:
未捕获的ReferenceError:$未定义
当我谷歌搜索它时,我发现这意味着在定义之前正在使用某些东西。我在python上很不错,但是javascript的极端新手,所以我不确定发生了什么。深入了解错误,我看到以下内容:
<script src="https://project.s3.amazonaws.com/static/js/chat.js"></script>
<script>
// For receiving
sender_id = "";
receiver_id = "1";
//For sending
$(function () { <<-- This is where the error is pointing to.
scrolltoend();
$('#chat-box').on('submit', function (event) {
event.preventDefault();
var message = $('#id_message');
send('', '', message.val());
message.val('');
})
})
</script>
</div>
上面的代码位于项目/ chat / templates / chat / chat.html中的html文件的底部,它通过{% static 'js/chat.js' %}
引用chat.js,上面是aws代码行生活在cloudhere:project / static_my_proj / js / chat.js。我正在集成的代码有'materialize.js'和'materialize.min.js'这样的东西,我试图理解它们的作用。
我想知道我是否尝试将两种类型的javascript结合起来。我完全迷失了。有没有人有任何指针?我能提供哪些代码可以提供帮助吗?
由于
答案 0 :(得分:3)
您必须添加以下行
private void initChartData(int mode) {
chart = (LineChart) findViewById(R.id.chart);
List<Entry> entries = new ArrayList<Entry>();
Calendar cal = Calendar.getInstance();
Calendar cal2 = Calendar.getInstance();
Date today = cal.getTime();
XAxis xAxis = chart.getXAxis();
xAxis.setGranularityEnabled(true);
xAxis.setGranularity(1f);
xAxis.setPosition(XAxis.XAxisPosition.BOTTOM);
switch (mode) {
case daily:
cal2.add(Calendar.DAY_OF_MONTH, -30);
Date thirtyDaysAgo = cal2.getTime();
dataObjects = realm.where(AmalStat.class).greaterThan("date", thirtyDaysAgo).and().lessThan("date", today)
.findAll().sort("date", Sort.DESCENDING);
Utils.logd("maxgettime: " + maxdaily);
mindaily = dataObjects.get(dataObjects.size() - 1).getDate().getTime();
Utils.logd("dataObjects size: " + dataObjects.size());
int k = dataObjects.size() < 6 ? dataObjects.size() : 5;
for (AmalStat data : dataObjects) {
Utils.logd("time: " + data.getDate().getTime() + ", point: " + data.getPoint());
entries.add(new Entry(data.getDate().getTime(), data.getPoint()));
Utils.logd("k: " + k);
if (k == 0) {
mindaily = data.getDate().getTime();
Utils.logd("min ini: " + mindaily);
}
k--;
}
rangedaily = maxdaily - mindaily;
xAxis.setValueFormatter(new MyAxisValueFormatter(mode));
xAxis.setLabelCount(entries.size(), true);
break;
case monthly:
int month = cal.get(Calendar.MONTH) + 1;
cal.set(Calendar.DAY_OF_MONTH, 0);
cal.set(Calendar.YEAR, cal.get(Calendar.YEAR));
cal.set(Calendar.MONTH, cal.get(Calendar.MONTH));
Date minDay = cal.getTime();
cal.set(Calendar.DAY_OF_MONTH, cal.getActualMaximum(Calendar.DAY_OF_MONTH));
cal.set(Calendar.YEAR, cal.get(Calendar.YEAR));
cal.set(Calendar.MONTH, cal.get(Calendar.MONTH));
Date maxDay = cal.getTime();
int year = cal2.get(Calendar.YEAR);
maxmonthly = maxDay.getTime();
minmonthly = minDay.getTime();
int j = 6;
xAxis.setLabelCount(6, true);
for (int i = month; i >= 0; i--) {
cal2.set(Calendar.MONTH, i - 1);
cal2.set(Calendar.YEAR, year);
cal2.set(Calendar.DAY_OF_MONTH, 1);
minDay = cal2.getTime();
cal.set(Calendar.DAY_OF_MONTH, cal.getActualMaximum(Calendar.DAY_OF_MONTH));
cal.set(Calendar.YEAR, cal.get(Calendar.YEAR));
cal.set(Calendar.MONTH, i - 1);
maxDay = cal.getTime();
SimpleDateFormat simpleDate = new SimpleDateFormat("dd/MM/yyyy");
String minDayText = simpleDate.format(minDay);
String maxDayText = simpleDate.format(maxDay);
Utils.logd(minDayText + " - " + maxDayText);
int wajibs = realm.where(AmalStat.class).greaterThan("date", minDay).and().lessThan("date", maxDay)
.sum("wajib").intValue();
int muakkads = realm.where(AmalStat.class).greaterThan("date", minDay).and().lessThan("date", maxDay)
.sum("muakkad").intValue();
int nonMuakkads = realm.where(AmalStat.class).greaterThan("date", minDay).and().lessThan("date", maxDay)
.sum("nonMuakkad").intValue();
int point = wajibs + muakkads + nonMuakkads;
entries.add(new Entry(cal2.getTimeInMillis(), point));
Utils.logd("i: " + i);
j--;
if (j == 0) {
Utils.logd("ini=" + i);
minmonthly = cal2.getTimeInMillis();
}
}
if (month < 12) {
for (int i = 12; i > month; i--) {
cal2.set(Calendar.MONTH, i - 1);
cal2.set(Calendar.YEAR, year - 1);
cal2.set(Calendar.DAY_OF_MONTH, 1);
int wajibs = realm.where(AmalStat.class).greaterThan("date", minDay).and().lessThan("date", maxDay)
.sum("wajib").intValue();
int muakkads = realm.where(AmalStat.class).greaterThan("date", minDay).and().lessThan("date", maxDay)
.sum("muakkad").intValue();
int nonMuakkads = realm.where(AmalStat.class).greaterThan("date", minDay).and().lessThan("date", maxDay)
.sum("nonMuakkad").intValue();
int point = wajibs + muakkads + nonMuakkads;
entries.add(new Entry(cal2.getTimeInMillis(), point));
Utils.logd("i: " + i);
j--;
if (j == 0) {
Utils.logd("itu=" + i);
minmonthly = cal2.getTimeInMillis();
}
}
}
rangemonthly = maxmonthly - minmonthly;
xAxis = chart.getXAxis();
xAxis.setValueFormatter(new MyAxisValueFormatter(mode));
break;
case annual:
break;
}
xAxis.setGranularityEnabled(true);
xAxis.setGranularity(1f);
xAxis.setPosition(XAxis.XAxisPosition.BOTTOM);
Collections.sort(entries, new EntryXComparator());
LineDataSet dataSet = new LineDataSet(entries, "Label"); // add entries to dataset
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
dataSet.setColor(getColor(R.color.white));
dataSet.setValueTextColor(getColor(R.color.white)); // styling, ...
} else {
dataSet.setColor(getResources().getColor(R.color.white));
dataSet.setValueTextColor(getResources().getColor(R.color.white)); // styling, ...
}
LineData lineData = new LineData(dataSet);
chart.setDescription(null); // Hide the description
chart.getAxisLeft().setDrawLabels(false);
chart.getAxisLeft().setDrawGridLines(false);
chart.getXAxis().setDrawLabels(true);
chart.getXAxis().setEnabled(true);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
chart.getXAxis().setTextColor(getColor(R.color.white));
} else {
chart.getXAxis().setTextColor(getResources().getColor(R.color.white));
}
chart.getAxisRight().setDrawLabels(false);
chart.getAxisRight().setDrawGridLines(false);
chart.getAxisRight().setDrawAxisLine(false);
chart.getLegend().setEnabled(false); // Hide the legend
chart.setData(lineData);
chart.invalidate();
switch (mode) {
case daily:
Utils.logd(rangedaily + " " + maxdaily + " " + mindaily);
chart.setVisibleXRangeMaximum(rangedaily);
chart.moveViewToX(maxdaily);
break;
case monthly:
Utils.logd(rangemonthly + " " + maxmonthly + " " + minmonthly);
chart.setVisibleXRangeMaximum(rangemonthly);
chart.moveViewToX(maxmonthly);
break;
case annual:
}
chart.invalidate();
Utils.logd("akhir");
}`
上面/之前
<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
这一行
答案 1 :(得分:0)
我认为你没有正确地声明变量。
变量,
var sender_id = "";
var receiver_id = "1";
// if you are using ES6 then
const sender_id="";
const receiver_id = "1";
应该像这样声明,
<script>
$(document).ready(function() {
$('#dataTables-example').DataTable({
responsive: true
});
});
</script>
<script>
$( function() {
$( "#datepicker" ).datepicker();
} );
</script>
除此之外,也许你应该像艾哈迈德·泽伊贝克所说的那样包括jquery。
Materialise.js和Materialize.css是materialize框架的一部分,类似于bootstrap。