我有一些查询,比如在jquery文件包含之后如何在最后位置包含js文件。但是现在的问题是我的js首先加载,然后加载我的jQuery文件。就像现在我添加了像:
这样的文件use frontend\assets\AppAsset;
AppAsset::register($this);
$this->registerJsFile('@frontend_base/web/js/sendverification.js');
所以这将添加js文件但不是最后一个。那我怎么能做到这一点?
答案 0 :(得分:4)
您实际上可以使您的脚本依赖于jQuery。这是唯一真正的方法,不使用包含模式奇怪,以确保这一点:
$this->registerJsFile('@frontend_base/web/js/sendverification.js', ['depends' => 'yii\web\JqueryAsset'])
使用POS_
常量只能确保JS包含在页面的某个部分,而不是在某个文件之后,并且可以包含在该文件之前。
您可以在此处阅读更多内容:http://www.yiiframework.com/doc-2.0/yii-web-view.html#registerJsFile()-detail
答案 1 :(得分:2)
您可以将Js文件的位置定义为Register Js File
$this->registerJsFile('@frontend_base/web/js/sendverification.js',['position' => \yii\web\View::POS_END]);
答案 2 :(得分:0)
推荐的解决方案是使用AssetBundles。类似的东西:
try:
aux = pd.read_csv('E:\Python_webscraping_Ahmd/news.csv')
except:
aux = pd.DataFrame(columns=list(news.columns))
aux.to_csv('E:\Python_webscraping_Ahmd/news.csv', encoding= 'utf-8', index=False)
with open('E:\Python_webscraping_Ahmd/news.csv', 'a') as f:
news.to_csv(f, header=False, index=False)
然后在您的视图文件中:
UnicodeEncodeErrorTraceback (most recent call last)
<ipython-input-12-8835f23065f2> in <module>()
75
76 if __name__ == '__main__':
---> 77 getDailyNews()
78
<ipython-input-12-8835f23065f2> in getDailyNews()
69
70 with open('E:\Python_webscraping_Ahmd/news.csv', 'a') as f:
---> 71 news.to_csv(f, header=False, index=False)
72
73 cleanData('E:\Python_webscraping_Ahmd/news.csv')
E:\Anaconda\lib\site-packages\pandas\core\frame.py in to_csv(self, path_or_buf, sep, na_rep, float_format, columns, header, index, index_label, mode, encoding, compression, quoting, quotechar, line_terminator, chunksize, tupleize_cols, date_format, doublequote, escapechar, decimal)
1401 doublequote=doublequote,
1402 escapechar=escapechar, decimal=decimal)
-> 1403 formatter.save()
1404
1405 if path_or_buf is None:
E:\Anaconda\lib\site-packages\pandas\io\formats\format.py in save(self)
1590 self.writer = csv.writer(f, **writer_kwargs)
1591
-> 1592 self._save()
1593
1594 finally:
E:\Anaconda\lib\site-packages\pandas\io\formats\format.py in _save(self)
1691 break
1692
-> 1693 self._save_chunk(start_i, end_i)
1694
1695 def _save_chunk(self, start_i, end_i):
E:\Anaconda\lib\site-packages\pandas\io\formats\format.py in _save_chunk(self, start_i, end_i)
1717 quoting=self.quoting)
1718
-> 1719 lib.write_csv_rows(self.data, ix, self.nlevels, self.cols, self.writer)
1720
1721
pandas\_libs\lib.pyx in pandas._libs.lib.write_csv_rows()
UnicodeEncodeError: 'ascii' codec can't encode character u'\u2014' in position 134: ordinal not in range(128)
依赖关系将确保class SendverificationAsset extends AssetBundle {
public $basePath = '@webroot';
public $baseUrl = '@web';
public $js = [
'js/sendverification.js'
];
public $depends = [
'yii\web\JqueryAsset'
];
}
的Javascript和/或CSS总是在JQuery包含的任何内容之后。
使用AssetBundles还可以让您轻松缩小/压缩代码以供生产使用。