Javascript

浏览模式: 标准 | 列表 | 图文
aliyun:One or more of the sp....

aliyun:One or more of the sp....

Aliyun oss 报错: One or more of the specified parts could not be found or the specified entity tag might not have matched the part's entity tag.

报错是在multipartUpload方法中。如果要解决也很方便,在跨域设置中,暴露的headers中增加一个:ETag,即可,就是这么简单,但,真心花了不少时间处理(最后要看这里:https://help.aliyun.com/document_detail/32069.htm,如果用了分片,还是要再加一个:etag和x-oss-request-id)
有点小意外的是。AliOss的文档中有写:oss.put(name, object ),说是第二个参数支持File和Blob对象(嗯,在浏览器中)
file {String|Buffer|ReadStream|File(only support Browser)|Blob(only support Browser)} object local path, content buffer or ReadStream content instance use in Node, Blob and html5 File
然而在实际使用的时候,却是报错:TypeError: Must provide String/Buffer/ReadableStream for put.,这,简直是忽悠人啊。再比如说,multipartUpload,他说:
file {String|File(only support Browser)|Blob(only support Browser)} file path or HTML5 Web File or web Blob
这回就真实是支持的。
----
难道区别就在于上面写的是:object local path而下面写的是 file path??
不管了。已解决。就是有点渗的慌
browser.min.js 报错:Cannot read property 'keys' of undefined

browser.min.js 报错:Cannot read property 'keys' of undefined

在IE下,果然什么样的问题都会发生,为了兼容旧版浏览器,大家都知道要加载browser.min.js。然而。。。问题还是来了,就象标题那样。

查了一些资料,发现很多人都遇到过,原来。。。。居然是browser.min.js的版本太高了,降为 5.8.24 ,世界清静了
然而还是遇到一点问题,为了想用一些新的语法,用了<script type="text/babel">,但这样却导致vue 中的变量无法识别。尴尬 ,这一点还没有想到好办法
没办法用纯VUE进行开发,只能先PHP+VUE进行混写了
非专业前端做页面要注意的几个事项

非专业前端做页面要注意的几个事项

为了该死的IE,可能会需要这样

1、如果你的代码里用到了ES6的语法,比如:const a = 1;或者 a(){}等,记得 加载 browser.min.js ,如果还要支持 promise,那就加载browser-polyfill.min.js,下载地址:https://cdn.jsdelivr.net/npm/browser-polyfill@3.20.2/index.min.js,或者先npm install babel-core@7,然后复制其中的browser.min.js到你的项目里。如果文件中不含polyfill,还得 单独去下载一下
2、如果页面中引用了一些第三方的jQuery组件,记得加载1.x的版本。因为 从2开始不支持IE8了。如果IE9以下,那是无所谓
有些东西,还是需要记录一下。都是坑啊。。。然而直到IE11,都对ES6支持不好。所以。browser.js还是跑不 掉
vue in ie11

vue in ie11

几个小问题记录一下

1、如果IE11打不开F12控制面板,可能是因为你是从win7的IE8升上来的,如果是这样,下载这个更新包:
Install the latest cumulative IE update :

http://www.microsoft.com/en-us/download/details.aspx?id=45134 (32 bit)
http://www.microsoft.com/en-us/download/details.aspx?id=45154 (64 bit)
2、在IE11下面你会发现VUE居然不解析,报错内容是说:mount(){ 这一行缺少;,这个在官方论坛里介绍,IE11不认这种语法简写,还是乖乖的用mount:function(){}这种写法吧。同理。如果你的函数在methods中也是 a(){},b(){}这样写的。乘早换成a:function(){},b:function(){}吧
记录一下,不然的话,虽然 说VUE支持IE9+,但你在IE11下也不正常。。。
即使微软说未来EDGE要换chrome的核心,但老机器 怎么办啊!!XP最高只支持IE8好象。希望我都是接一些高端点的活(如果钱给够,IE8我也可以吐血支持)
tinymce 5 的dialog不再支持iframe了

tinymce 5 的dialog不再支持iframe了

尝试整个vue+tinymce的时候遇到点问题(之前说过,本来是用quillJS的。但如果要发表的内容支持那些微信编辑器里复制过来的内容。quill自己定义过的一些虚拟DOM就不支持了)

希望是美好的,实现起来是麻烦的,最后我放弃所有的选项,改用弹框iframe的形式。然而,问题就这么来了,tinymce5的dialog居然不支持iframe了。比如你看这个:https://github.com/tinymce/tinymce/issues/4786,官方直接说不支持了。NND

不过有人提示说,可以利用htmlpanel,直接在htmlpanel的html标签里,用<iframe。。。然后我试了一下。。居然真的OK

好吧,直接参考 这个了!https://github.com/tinymce/tinymce/issues/4786#issuecomment-463827289

JS文件:

function FileManager(callback, value, meta) {
var windowManagerURL = "/FilManage";// filemanager path

var windowManagerCSS = '<style type="text/css">' +
'.tox-dialog {max-width: 100%!important; width:97.5%!important; overflow: hidden; height:95%!important; border-radius:0.25em;}' +
'.tox-dialog__header{ display:none!important; }' +// for custom header in filemanage
'.tox-dialog__footer { display: none!important; }' +// for custom footer in filemanage
'.tox-dialog__body { padding: 0!important; }' +
'.tox-dialog__body-content > div { height: 100%; overflow:hidden}' +
'</style > ';
window.tinymceCallBackURL = '';
window.tinymceWindowManager = tinymce.activeEditor.windowManager;
tinymceWindowManager.open({
title: '',
body: {
type: 'panel',
items: [{
type: 'htmlpanel',
html: windowManagerCSS+ '<iframe src="' + windowManagerURL + '" frameborder="0" style="width:100%; height:100%"></iframe>'
}]
},
buttons: [] ,
onClose: function () {
if (tinymceCallBackURL!='')
callback(tinymceCallBackURL, {}); //to set selected file path
}

} );
}

iframe中:

var windowManager = top != undefined && top.tinymceWindowManager != undefined ? top.tinymceWindowManager : '';


if (windowManager != '') {
if (top.tinymceCallBackURL != undefined)
top.tinymceCallBackURL = path;
windowManager.close();
}
vue-nprogress-pjax 插件

vue-nprogress-pjax 插件

基于昨天写的vue+blade+(vue-pjax-adapter),发现没有任何进度提示,感觉比较不直观,但vue-pjax-adapter不能注入方法(或许是我不会)。

在app.js里引入了nprogress后。在axios请求前尝试注入,比如:
window.axios.interceptors.request.use((config) => {
console.log(before);
NProgress.configure({easing: 'ease', speed: 1000, showSpinner: true});
NProgress.start();
return config;
});
window.axios.interceptors.response.use((response) => {
NProgress.done();
console.log(after);
return response;
}, (error) => {
return Promise.reject(error);
});
但是没有看到有任何需求。才尝试修改了一下vue-pjax-adapter插件
用法和vue-pjax-adapter完全一样:
import nPjaxAdapter from 'vue-nprogress-pjax';
window.Vue.use(nPjaxAdapter);
/**
* 如果不是标准的pjax-container,就是这样使用
* // window.Vue.use(nPjaxAdapter, {
// targetSelector: '#my-custom-target',
// });
*/
就这样简单。现在切换页面有进度条了
代码在这里:https://www.npmjs.com/package/vue-nprogress-pjax
post的奇技淫巧:Post the checkboxes that are unchecked

post的奇技淫巧:Post the checkboxes that are unchecked

放到javascript里为实在是意外 。主要是这应该是属于前端的事情。

起因是这样的,一个checkbox,在没有选中前提交。POST过来的数据中。连checkbox对应的name的KEY,在$_POST中就不存在。这个就尴尬了。因为正常操作是form.submit(),或者是用$.post('xxx',$('#form').serializeArray())。这两种情况下,未选中的checkbox直接就消失在$_POST中了
表单的KEY比较多,将近20个(有点夸张,但是是事实)。如果一个个的写 var xxx = $('xxx:checked').val()||0; 这样也好痛苦的说~~
网上找了一下,看到这个:https://stackoverflow.com/questions/1809494/post-the-checkboxes-that-are-unchecked,
投票最高的居然是:
<form>
<input type='hidden' value='0' name='selfdestruct'>
<input type='checkbox' value='1' name='selfdestruct'>
</form>
原理就是,如果selfdestruct有值,默认下面有值的会覆盖上面的。因为一个FORM里同名的key只能有一个。如果selfdestruct没有选中,那么就会用hidden里的值!
jqweui 的 select/picker 控件添加清除

jqweui 的 select/picker 控件添加清除

jqweui是一个偷懒的基于Weui的组件,1.0的时候已经部分支持rem。所以用的还是比较多的。特别是我对它的部分组件有了一些扩展。而且它还有一些奇技淫巧。

1、如何通过函数来动态调整picker的内容。

默认情况下,picker/select在初始化的时候值已经固定了。这时候你其实是没有办法调整的,但不代表没有办法。虽然 API里没有提供,读了源码后你就能发现。其实你可以这样:

$('#xxx').val('').data('weui-select',false).select({
title: "其他值",
items: ["1","2"]
});

记得有一个恶心的地方,items里的值不能是数字!!!

2、添加清除功能,默认的select/picker在选择后就不能清除了(当然你可以在items的第一个值设置为空)。所以我简单的扩展了一下:https://github.com/lihongxun945/jquery-weui/issues/443。

无非就是加个文字,加个清除等等。。

3、picker/select在使用的时候,有时候会显示一个软键盘而无法删除和隐藏。这时候的解决办法其实就是在input上面加上onfocus="this.blur()"即可!

New user help: columns vs. columnDefs for client side rendering of AJAX data

New user help: columns vs. columnDefs for client side rendering of AJAX data

说实话,在datatables里,我觉得这个回复挺重要的!https://datatables.net/forums/discussion/33723/new-user-help-columns-vs-columndefs-for-client-side-rendering-of-ajax-data

提问:
Hi,

I'm a beginner with DataTables. I'm trying to use DataTables AJAX to pull records from the server (an ASP.NET MVC app.) Each record coming from the server has name, address line 1, address line 2, city, state, zip. I want my table to combine and format all those fields into one column on the client.

My questions are:
1. Would I use columns.render, or columnDefs.render?
2. Do I need both columns and columnDefs?
3. Do I need to specify either the table column name (e.g., NameAndAddress) in "columns", or do I need to list each field coming back from the server?
4. How do I use "targets"? Does "targets" refer to the column in the displayed table, or the column under "columns"?

Thanks for your help. I've been though the documentation a few times and I'm still confused about columns vs. columnDefs.
回答:

"columns" & "columnsDefs" ultimately serve the same purpose.

The differences being:

  1. "columns" requires you to provide a configuration or null for all columns. "columnDefs" requires you to only proved configuration for columns that have "special" configurations
  2. I have found "columns" best used if handling array of strings as your rows. I have found "columnDefs" best used if handling objects as your rows

"targets" takes a single string or int value, or array of previous two to denote which columns this configuration is for. I suggest using column class instead of column # in the event you want to use ColReorder extension.

Here are examples of how I have configured columns in my application.

HTML:
<th class="actionsCol no-print">Actions</th>
<th class="StatusCol">Status</th>
<th class="IsFinalCol">Final<br>Plan</th>
<th class="VrsnCol">Vrsn</th>
<th class="CutCntCol">Cut<br>Cnt</th>
<th class="CarCntCol">Car<br>Cnt</th>
JS关键代码:
"columnDefs": [
{
// This is for the Action column icons
"targets": 'actionsCol',
"sorting": false,
"orderable": false,
"type":"html",
"width": "8%",
className: "dt_nowrap_col no-print",
"render": function (data, type, row) {
return $.jqote(yv.templates.action_icons, data);
}
},
{
"targets": ['IsFinalCol','CutCntCol','CarCntCol','VrsnCol','StatusCol'],
"width": "5%"
},
etc
]
看到这些定义,估计你应该能够想得出如何更好的应用了吧?
----EOF---
其他参考 :
datatables的一些常用的玩意

datatables的一些常用的玩意

datatables现在也开始逐步用的多了。虽然用起来复杂了一点,但好歹还能减少一些开发量

1、语言包,这个就不用说了,直接找个中文语言包即可(就是有些用插件的要注意一下,还是多写)
2、表格居中居右,这些不太好控制 ,但可以在每个columns里定义一个:sClass,这时候你就想怎么样就行了。例
{data:"xxx",sClass:"text-right"}
然后你加一个样式.text-right{text-align:right}
轻轻松松
3、POST,默认datables的数据是用GET请求,如果你参数过多,会造成GET参数过长的问题,这时候就只能用POST了。只是用了POST,数据就没有缓存了(可以用cache自己处理,但是麻烦)
4、columns的render可以写自定义事件。能封装起来一起用是最好的,毕竟每个页面的每个表格的Render都有可能会复用,要是每个地方都写同一份就太累了
5、事件,这一块说容易 也容易 也麻烦也麻烦。还是根据实际情况吧。反正你只要 保持你在Render的时候将每行数据的主键写出来,到时候想怎么处理都OK