小编Rya*_*P13的帖子

jQuery 试图将工具提示放在悬停的元素上

我正在编写自己的工具提示功能,如下所示:

$(".tip_holder").hover(
  function() {

      var $containerWidth = $(this).width();

      var $containerHeight = $(this).height();

      var $tipTxt = $(this).text();

      var $tipTitle = $(this).attr('title');

      var $offset = $(this).offset();

      $('#icis_dashboard').prepend('<div id="tooltip">' + $tipTxt + '</div>');

      $('#tooltip').css({
          'position': 'absolute'
      });

      var $tipWidth = $('#tooltip').width();

      var $tipHeight = $('#tooltip').height();

      $('#tooltip').css({
          'top': $offset.top - ($tipHeight + 5),
          'left': $offset.left,
          'padding': '0 5px 5px'              
      });

  },
  function() {
      $('#tooltip').remove();
  }
);
Run Code Online (Sandbox Code Playgroud)

但是,我无法将工具提示居中放置在我悬停的元素上。我需要将其缩放到悬停的任何大小元素。

我很欣赏有许多插件可以实现此功能,但我想编写自己的插件,以便工具提示 div 只会出现在代码中的同一位置,以便我的测试人员可以对其进行测试。这是他的要求,让他的生活更轻松:(

jquery jquery-plugins

2
推荐指数
1
解决办法
1万
查看次数

如何对服务中调用过滤器进行单元测试

我无法断言我的过滤器已在返回承诺后被调用.

从控制器调用此代码,然后控制器从http GET服务中提取数据以进行过滤:

getPermissions(){
    return this.DataService.getPermissionsLOV().then((data) => {
        return this.$filter('chunkCollection')(data, 3);
    });
}
Run Code Online (Sandbox Code Playgroud)

我的测试用例看起来像这样:

it('should get the permissions', () => {
    spyOn(service, 'getPermissions').and.callThrough();
    spyOn(DataService, 'getPermissionsLOV').and.callFake(function(){
        var defer = this.$q.defer();
        defer.resolve(mockData);
        return defer.promise;
    });

    let resp;

    service.getPermissions().then((data) => {
        resp = data;
    });

    scope.$digest();

    expect(service.getPermissions).toHaveBeenCalled();
    expect(DataService.getPermissionsLOV).toHaveBeenCalled();
    expect(resp).toEqual(mockData);

});
Run Code Online (Sandbox Code Playgroud)

断言expect(resp).toEqual(mockData);失败,因为响应被过滤chunkCollection但我不知道如何测试此调用$filter

我已经单独测试过滤器本身,所以知道它正在工作,业力告诉我它在报告上述断言的失败时正在转换数据.

javascript filter spy jasmine angularjs

2
推荐指数
1
解决办法
1848
查看次数

有没有办法让 ESLint 报告的唯一错误

我正在使用 TypeScript 和 React 重构现有项目。我介绍了 ESLint,代码中报告了 300 多个错误。

这是一项相当大的任务,因为 ESLint 本身无法自动修复这些问题。

有没有办法从 ESLint CLI 输出中获取不同的错误,然后使用该规则获取引发规则错误的文件,以便我可以逐个规则而不是逐个文件地修复它?

javascript command-line-interface typescript eslint

2
推荐指数
1
解决办法
204
查看次数

带有 babel eslint 解析的打字稿铸造

在将 ESLint 引入现有的 Typescript 代码库后,我遇到了一些解析错误。

我已经修复了大部分 lint 错误,但是babel-eslint作为解析器会抛出很多这样的错误:

  23:32  error  Parsing error: Unexpected token, expected ","

  21 |       return state.set(
  22 |         'callsInProgress',
> 23 |         (state.callsInProgress as any).filter(i => i !== action.payload)
     |                                ^
  24 |       );
  25 |     }
  26 |     case actions.API_RESET: {
Run Code Online (Sandbox Code Playgroud)

我认为这是因为babel不了解类型转换as any

我如何通过解析器得到这个?

我的 babel 配置如下:

module.exports = {
  presets: ['@babel/preset-env', '@babel/preset-react', '@babel/preset-typescript'],
  plugins: ['@babel/plugin-proposal-class-properties', '@babel/plugin-transform-runtime', '@babel/plugin-transform-typescript']
};
Run Code Online (Sandbox Code Playgroud)

typescript eslint babeljs babel-eslint

2
推荐指数
2
解决办法
5577
查看次数

jQuery quickSearch 插件在点击提交按钮时触发,而不是在输入上绑定事件

我正在使用 jQuery quickSearch 插件来过滤列表:

http://lomalogue.com/jquery/quicksearch/

但是我想过滤点击提交按钮而不是插件本身提供的默认绑定。

我尝试了以下方法无济于事:

    $(function(){
    var $qs = $('input#id_search').quicksearch('table#table_example tbody tr');

    $('#mySubmit').click(function () {
        $qs.go();
        return false;
    });

});
Run Code Online (Sandbox Code Playgroud)

随附的 html 是:

<form action="#">
            <fieldset>
                <input type="text" name="search" value="" id="id_search" />
                <input type="submit" name="mySubmit" id="mySubmit" value="Search table" />              
            </fieldset>
        </form>

    <table id="table_example">
        <thead>
            <tr>

                <th>Email</th>
                <th>Id</th>
                <th>Phone</th>
                <th>Total</th>
                <th>Ip</th>
                <th>Url</th>

                <th>Time</th>
                <th>ISO Date</th>
                <th>UK Date</th>
            </tr>
        </thead>
        <tbody>
            <tr>

                <th>devo@flexomat.com</th>

                <td>66672</td>
                <td>941-964-8535</td>
                <td>$2482.79</td>
                <td>172.78.200.124</td>

                <td>http://gmail.com</td>
                <td>15:10</td>

                <td>1988/12/14</td>
                <td>14/12/1988</td>
            </tr>

            <tr>

                <th>henry@mountdev.net</th>

                <td>35889</td>

                <td>941-964-9543</td>
                <td>$2776.09</td>
                <td>119.232.182.142</td>

                <td>http://www.gmail.com</td>
                <td>3:54</td> …
Run Code Online (Sandbox Code Playgroud)

jquery jquery-plugins

1
推荐指数
1
解决办法
1756
查看次数

将字符串拆分为成对数字的数组

我试图找出如何将以下十六进制字符串拆分成一个配对数字的数组.

目前我有以下内容:

function getRGB(hexVal) {

    var substrHexVal = hexVal.substring(1,hexVal.length);

    var splitHexVal = substrHexVal.split("");

    return splitHexVal;

}

var a = getRGB("#00FF00");

a;
Run Code Online (Sandbox Code Playgroud)

返回以下内容:

["0", "0", "F", "F", "0", "0"]
Run Code Online (Sandbox Code Playgroud)

但我需要得到这个:

["00", "FF", "00"]
Run Code Online (Sandbox Code Playgroud)

可能很明显我想做什么,但我想自己做其余的事情.

javascript arrays

1
推荐指数
1
解决办法
2189
查看次数

在ExtJS 4.0 Combobox中选择全部

我有一个ExtJS Combobox,要求是有一个额外的值,用户可以从第一个值中选择所有选项,如下所示:

Ext.onReady(function () {
    // The data store containing the list of states
    var states = Ext.create('Ext.data.Store', {
        fields: ['abbreviation', 'name'],
        data: [{
            name: 'Select all',
            abbreviation: 'ALL'
        },
        {
            name: 'ALABAMA',
            abbreviation: 'AL'
        }, {
            name: 'ALASKA',
            abbreviation: 'AK'
        }, {
            name: 'AMERICAN SAMOA',
            abbreviation: 'AS'
        }, {
            name: 'ARIZONA',
            abbreviation: 'AZ'
        }, {
            name: 'ARKANSAS',
            abbreviation: 'AR'
        }, {
            name: 'CALIFORNIA',
            abbreviation: 'CA'
        }, {
            name: 'COLORADO',
            abbreviation: 'CO'
        }, {
            name: 'CONNECTICUT',
            abbreviation: 'CT'
        }, { …
Run Code Online (Sandbox Code Playgroud)

combobox extjs store extjs4

1
推荐指数
1
解决办法
5679
查看次数

从格式不正确的XML创建格式良好的XML

我不得不使用从Web服务返回的以下XML:

<?xml version="1.0" encoding="utf-8" ?>
<root>
  <staticPage>
    <liStaticPageID>6165</liStaticPageID>
    <sTitle>Ethylene</sTitle>
    <sPageURL>Ethylene.htm</sPageURL>
    <sBody>
      <P>Ethylene is a colourless, odourless, extremely flammable compressed gas. It is slightly soluble in water and soluble in liquid hydrocarbons. It reacts with strong oxidants causing fire and explosion hazard. It may polymerise to form aromatic compounds under the influence of temperatures above 600°C.</P>
      <BR>
        <P>Around 59% of the world’s ethylene demand is consumed in polyethylene production. Other major derivatives are ethylene oxide/glycol (13%), ethylene dichloride/vinyl chloride monomer (13%) …
Run Code Online (Sandbox Code Playgroud)

xml ajax jquery

0
推荐指数
1
解决办法
785
查看次数

在Javascript中从URL中提取数字ID

与我之前的问题类似:

在Javascript中拆分字符串

URL现在已更改,唯一编号ID不再位于URL的末尾,如下所示:

/MarketUpdate/Pricing/9352730/Report
Run Code Online (Sandbox Code Playgroud)

我如何从此提取数字现在我不能使用以前的解决方案?

javascript regex string

0
推荐指数
1
解决办法
1470
查看次数

在列表元素中锚定不填充显示的可用空间:块和高度/宽度设置为100%

在下面的小提琴中,我希望锚元素占据其父元素的所有可用空间:

http://jsfiddle.net/nmxmT/

看不出我做错了什么:(

html css css3

0
推荐指数
1
解决办法
1606
查看次数

自定义组件不是 Angular CLI 应用程序中的已知元素

我正在考虑使用 Angular CLI 学习 Angular 8。

我向核心模块添加了两个新组件,然后将其导入应用程序模块。

当我尝试在我的应用程序 html 中呈现组件时,控制台中会抛出“未知元素”错误。

我不确定为什么?

这是我的 app.module.ts

import { BrowserModule } from "@angular/platform-browser";
import { NgModule } from "@angular/core";

import { AppComponent } from "./app.component";
import { NoopAnimationsModule } from "@angular/platform-browser/animations";
import { CoreModule } from "./core/core.module";

@NgModule({
  declarations: [AppComponent],
  imports: [BrowserModule, NoopAnimationsModule, CoreModule],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule {}
Run Code Online (Sandbox Code Playgroud)

我的 core.module.ts

import { NgModule } from "@angular/core";
import { CommonModule } from "@angular/common";
import { InputComponent } from "../input/input.component";
import …
Run Code Online (Sandbox Code Playgroud)

javascript components angular-cli angular

-2
推荐指数
1
解决办法
119
查看次数