我已经使用fetch创建了对象,我正在尝试使用polyfill使其在IE11上工作,但它无法正常工作。我尝试使用https://github.com/stefanpenner/es6-promise https://github.com/taylorhakes/promise-polyfill https://github.com/github/fetch
在我脑海里,我有
<!-- Bootstrap -->
<link href="/assets/bootstrap/dist/css/bootstrap.min.css" rel="stylesheet" />
<link href="/assets/bootstrap/dist/css/bootstrap-theme.min.css" rel="stylesheet" />
<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<script src="/assets/jquery/dist/jquery.js"></script>
<script src="/assets/jquery-ui/jquery-ui.js"></script>
<script src="/assets/fetch/fetch.js"></script>
<script src="/assets/es6-promise/dist/es6-promise.min.js"></script>
JavaScript代码
//To add to window
if (!window.Promise) {
window.Promise = Promise;
}
const CommsMatrix = {
getCMDStatuses: function(){
return fetch('/api/user/list/comms/matrix/data/format/json'+'?csrf='+$.csrfParam('csrf')+'&select=distinct(status)&orderby=status', {
// body: new URLSearchParams({ csrf: $.csrfParam('csrf'), select:
// 'distinct(status)', orderby: 'status' })
credentials: 'include'
})
.then(response => {
return response.headers.error ? Promise.reject(response.headers.error) : response.json();
}).then(body => {
return body.body.recordset.record.map(v => v.STATUS)
})
},
getSupportedProtocols: function(){
return fetch('/api/user/list/sys/list/protocols/format/json'+'?csrf='+$.csrfParam('csrf')+'&orderby=name', {
// body: new URLSearchParams({ csrf: $.csrfParam('csrf'), orderby:
// 'name' })
credentials: 'include'
})
.then(response => {
return response.headers.error ? Promise.reject(response.headers.error) : response.json();
}).then(body => {
return body.body.recordset.record.map(v => v.NAME)
})
}
}
Promise.all([CommsMatrix.getCMDStatuses(), CommsMatrix.getSupportedProtocols()])
// Destructuring the 2-item array into statuses and protocols variables
.then(([ statuses, protocols ]) => {
// You've got statuses and protocols loaded
selectField = HTMLFormTag.createSelect(statuses, true, false, 'To implement');
selectField.setAttribute("name", 'status['+counter+']');
selectField = selectField.outerHTML;
selectProtocolField = HTMLFormTag.createSelect(protocols, true, false, 'TCP');
selectProtocolField.setAttribute("name", 'protocol['+counter+']');
selectProtocolField = selectProtocolField.outerHTML;
// Automatically add a first row of data
$('#addRow').click();
});
在IE11中,它在3个地方抱怨。 .then(response => {
以及.then(([ statuses, protocols ]) => {
和SCRIPT438: Object doesn't support property or method 'csrfParam'