我正在研究一个查看页面上的表值列表的函数,如果列标题包含任何部分output,它将相应地转换该值.
function createLink(field, val) {
var output = {
'ntid': 'https://internal/profile/' + val,
'email': 'mailTo:' + val
};
var i, key, keys = Object.keys(output);
for ( i = 0; i < keys.length; ++i ) {
key = keys[i];
if ((field.toLowerCase()).includes(key)) {
return '<a href="'+output[key]+'" target="_blank">'+val+'</a>';
}
}
return val;
}
Run Code Online (Sandbox Code Playgroud)
我遇到的问题是IE .includes()在行上引发错误,指出"对象不支持属性或方法'包含'".
我有点麻烦让它按原样运行,但没有意识到includes()必须是并非所有浏览器都支持的东西.
还有什么我可以用来代替这个,以支持跨浏览器支持吗?
我正在使用jQuery getScript将X量的js文件加载到我的页面中.每个JS页面都有一个AJAX调用,用于从数据库中获取数据.
我正在使用.done方法getScript来查看所有文件何时加载但我需要等到所有的AJAX调用都已完成.
getScript在做某事之前,我怎样才能等待AJAX调用完成包含的文件?
$.getMultiScripts(moduleIncludes, 'includes/js/modules/').done(function() {
// All of the JS files have been included but we need to wait until those files have finished their AJAX call.
});
// Get array of JS scripts to load
$.getMultiScripts = function(arr, path) {
var _arr = $.map(arr, function(scr) {
return $.getScript((path || "") + scr);
});
_arr.push($.Deferred(function(deferred) {
$(deferred.resolve);
}));
return $.when.apply($, _arr);
}
Run Code Online (Sandbox Code Playgroud) 我有一个对象数组,其中一些对象值包含我需要删除的HTML标记.
我尝试循环它然后unwrap()在元素上使用jQuery函数但我收到的错误unwrap不是函数.
var tempData = w2ui.grid.records;
// Modify our tempData records to remove HTML
$.each(tempData, function(key, value) {
value.unwrap('a');
});
Run Code Online (Sandbox Code Playgroud)
我的结构如下:
Array [
Object,
Object,
Object
]
Run Code Online (Sandbox Code Playgroud)
对象/属性的示例:
Object = {
Name: 'Bob',
email: 'bob@gmail.com'
website: '<a href="http://www.example.com">Example.com</a>'
}
Run Code Online (Sandbox Code Playgroud)
修改对象后的所需输出:
Object = {
Name: 'Bob',
email: 'bob@gmail.com'
website: 'Example.com'
}
Run Code Online (Sandbox Code Playgroud)
这是我开始的一个简单的例子:https://jsfiddle.net/zcwk1kw6/
该示例显示了包含HTML的单个值,但我的最终目标是从任何值中删除所有HTML,而不是针对特定属性.
什么是最好的方法来解决这个问题?
我有一个 javascript 循环,它迭代数据库中的一些注释并将它们连接成一个字符串以附加到 DOM。它使用noteType作为键,因此我可以在多个选项卡上分隔不同类型的笔记。
问题是,我需要显示按日期排序的所有笔记的组合视图。因此,在循环结束时,我将笔记附加到一个单独的变量中,我combinedOutput称之为注释类型。然而,当需要将它们全部组合为一个时,两组正确排序的数组将按各自的顺序附加,并在最终输出中丢弃日期顺序。
这是我的代码的示例:
// Define our vars
var output = [],
combinedOutput = [],
noteType = '',
noteDate = new Date;
$(data).find('notes>data').each(function() {
var $p = $(this);
noteType = $p.find('noteType').text(),
noteDate = moment.utc($p.find('timestampOrig').text()).toDate()
if (typeof(output[noteType]) == 'undefined') {
output[noteType] = "";
}
if (typeof(combinedOutput[noteDate]) == 'undefined') {
combinedOutput[noteDate] = new Date;
}
// Create our note
output[noteType] += '<div id="message_' + $p.find('recordID').text() + '" class="panel panel-default custom-panel item">';
output[noteType] += 'Something Here';
output[noteType] …Run Code Online (Sandbox Code Playgroud) 我有一个订阅ngOnInit生命周期中的行为主题的组件.此组件html用于ngIf在呈现表之前查看数据是否存在.
当我离开页面时,我想确保下次回来时,表格不可见,直到再次获取该数据.到目前为止,我能够做到这一点的唯一方法是在主题上调用next并发送一个空字符串,这感觉不对..
零件:
mapMetaData: any;
ngOnInit() {
// Subscribe to our map data
this._mapsService.uiMapMetaData
.subscribe(
results => {
if (results) {
this.mapMetaData = results;
}
}
);
}
/**
* Implement onDestroy life cycle
*
* @memberof ViewMapComponent
*/
ngOnDestroy() {
this._mapsService.updateMapMetaData('');
}
Run Code Online (Sandbox Code Playgroud)
HTML:
<span *ngIf="mapMetaData">
<div class="page-header">
<h3 class="text-primary">{{ mapMetaData.TargetName }} <small>{{ mapMetaData.TargetDesc }}</small>
<button type="button" class="btn btn-default btn-sm pull-right" role="button" (click)="backToMaps()">
<i class="fa fa-arrow-left"></i> Back to Maps
</button>
</h3>
</div>
<app-map-versions [targetID]="targetID"></app-map-versions>
<app-map-exceptions [targetID]="targetID"></app-map-exceptions>
<app-map-rules></app-map-rules> …Run Code Online (Sandbox Code Playgroud) 我有一个从对象呈现的数据表。具体来说,表的每一行都是来自数组的值。
我需要能够根据单击的按钮在数组中上下移动对象。
var obj = [{
"RuleDetailID": "11624",
"AttributeValue": "172",
"Value": "Account Manager",
"IsValueRetired": "0"
}, {
"RuleDetailID": "11626",
"AttributeValue": "686",
"Value": "Agent",
"IsValueRetired": "0"
}, {
"RuleDetailID": "11625",
"AttributeValue": "180",
"Value": "Analyst",
"IsValueRetired": "0"
}, {
"RuleDetailID": "11629",
"AttributeValue": "807",
"Value": "Individual Contributor",
"IsValueRetired": "0"
}, {
"RuleDetailID": "11627",
"AttributeValue": "690",
"Value": "Senior Agent",
"IsValueRetired": "0"
}];
// Exmaple only, just rendering a table
function renderExample() {
var table = '';
for (var key in obj) {
table += …Run Code Online (Sandbox Code Playgroud)我有一个组件,允许用户填写一些字段以及选择个人资料图片。提交表单后,我试图清除它,以便他们可以添加另一个条目。
组件 HTML:
<input type="file" #userPhoto name="userPhoto" id="userPhoto" (change)="onFileChange($event)" />
Run Code Online (Sandbox Code Playgroud)
组件 TS:
@ViewChild('userPhoto') userPhoto: any;
...
private prepareSave(value): any {
const Image = this.userPhoto.nativeElement;
if (Image.files && Image.files[0]) {
this.userPhoto = Image.files[0];
}
const ImageFile: File = this.userPhoto;
const formData: FormData = new FormData();
formData.append('ParentUserID', value.parentUserID);
formData.append('FirstName', value.firstName);
formData.append('LastName', value.lastName);
formData.append('Age', value.age);
formData.append('Photo', ImageFile, ImageFile.name);
return formData;
}
...
<Submit Form>
clearSelectedPhoto() {
this.userPhoto.nativeElement.value = null;
}
Run Code Online (Sandbox Code Playgroud)
现在,我认为问题是我viewChild正在使用any而不是ElementRef. 但是,当我更改此设置时,打字稿会抱怨我在prepareSave方法中的行:
const ImageFile: File …Run Code Online (Sandbox Code Playgroud) 我有一个javascript函数,用于将一些JSON数据转换为excel导出。在大多数情况下,一切都很好。
但是,我注意到我的一个列名中现在有一个逗号(故意)LastName, FirstName。
使用我现有的代码,当我希望它是一个单列标题时,它会导致标题列被分离并移到其自己的列中。
/**
* Convert the JSON to a CSV File
* @param {*} JSONData
* @param {*} ReportTitle
* @param {*} ShowLabel
*/
function JSONToCSVConvertor(JSONData, ReportTitle, ShowLabel) {
//If JSONData is not an object then JSON.parse will parse the JSON string in an Object
var arrData = typeof JSONData != 'object' ? JSON.parse(JSONData) : JSONData;
var CSV = '';
//This condition will generate the Label/Header
if (ShowLabel) {
var row = "";
//This …Run Code Online (Sandbox Code Playgroud) 我有一个我正在研究的查询,它会进行一些数学运算,特别是总数和百分比.由于这些数据是基于所选日期范围的可选数据,因此有时可能无法运行此数学运算.
在这种情况下,我得到零除错误.
SELECT (
SELECT COUNT(s.ScoreID) AS TotalSamples,
COUNT(CASE WHEN qd.QDResultDesc = 'Pass' THEN 1 END) AS Pass,
COUNT(CASE WHEN qd.QDResultDesc = 'Pass' THEN 1 END) * 100 / COUNT(s.ScoreID) AS Quality,
COUNT(CASE WHEN qd.QDResultDesc = 'Fail' THEN 1 END) AS Fail,
COUNT(CASE WHEN qd.QDResultDesc = 'Fail' THEN 1 END) * 100 / COUNT(s.ScoreID) AS Error
FROM SubmissionScore AS s
JOIN gSubmission AS sub
ON sub.SubmissionID = s.RecordID
JOIN gQDResult AS qd
ON s.QDResultID = qd.QDResultID
JOIN resources.emp.Employees as e …Run Code Online (Sandbox Code Playgroud) 我有一个 bootstrap 3 按钮,它使用很棒的字体作为图标。我试图将按钮上的文本居中,但将图标与左侧对齐。
<button type="button" class="btn btn-default btn-lg btn-block">
<i class="fa fa-home pull-left"></i> Home
</button>
Run Code Online (Sandbox Code Playgroud)
当我使用 时pull-left,没有填充或边距,因此图标太靠近边缘(图 1)。
但是,当我尝试向图标添加margin-left或padding-left时,它也会将文本移动到右侧(应保持居中)。
在这些图标上使用边距或填充时,有没有办法不将文本推倒?
javascript ×6
jquery ×3
angular ×2
html ×2
typescript ×2
ajax ×1
arrays ×1
css ×1
observable ×1
sorting ×1
sql ×1
sql-server ×1
strip ×1