小编Ign*_*Ara的帖子

Android如何将int转换为String?

我有一个int,我想将其转换为字符串.应该简单吧?但编译器抱怨它在我这样做时找不到符号:

int tmpInt = 10;
String tmpStr10 = String.valueOf(tmpInt);
Run Code Online (Sandbox Code Playgroud)

上面有什么问题?而且,如何将int(或long)转换为String?

编辑:valueOf not valueof;)

android

76
推荐指数
4
解决办法
27万
查看次数

jQuery ajax()函数忽略了Firefox中的dataType参数

我正在尝试使用jQuery.ajax()来获取一些html,但Firefox正在给我一个"文件元素之后的垃圾"错误消息.正如这里这里所解释的那样,问题似乎是Firefox期望来​​自服务器的XML,并且当它没有正确解析时会抛出错误.这是我的ajax代码:

jQuery.ajax({
    url: name,
    dataType: "html",
    success: function(result) {
        console.log(result);
    },
    error: function (jqXHR, textStatus, errorThrown) {
        console.log(errorThrown);
    }
});
Run Code Online (Sandbox Code Playgroud)

服务器返回带有这些响应头的html:

Accept-Ranges   bytes
Content-Length  2957
Last-Modified   Tue, 02 Jul 2013 16:16:59 GMT
Run Code Online (Sandbox Code Playgroud)

请注意,没有内容类型标头.我确信添加一个可以解决问题,但这不是一个选择.

真正的问题是Firefox似乎忽略了ajax调用中的dataType:参数.我也尝试添加contentType:并接受:参数,但它没有帮助.

我在这里错过了什么?如何强制Firefox以纯文本形式处理响应?

javascript ajax firefox jquery

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

通过ajax发布表单并在play框架java中获取表单对象

我正在使用play framework 2.3.8 java并使用ajax提交表单,但我无法从该请求中获取Form对象.我的问题解释如下.我有一个模特

@Entity
public class Permission {
    @Id
    @Column(name = "id", nullable = false)
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;

    private String per1= "off";

    private String per2= "off";

    // getter setters
}
Run Code Online (Sandbox Code Playgroud)

我的表格

<form id="form-permission">
    <!--Setting "on" and "of" value from js-->
    <input type="checkbox" id="per1" name="per1">
    <input type="checkbox" id="per2" name="per2">
    <input type="submit" >
</form>

$('#form-permission').on('submit',function(){
    var uid=// id to update

    myJsRoutes.controllers.MyController.updatePer(uid).ajax({

    data : $("#form-permission").serialize(),
        success : function(data) {
            console.log(data);
    });
    return false;
});
Run Code Online (Sandbox Code Playgroud)

当提交没有ajax的表单时, play会将请求数据绑定到模型Object,我们可以获得Form对象 …

java forms ajax jquery playframework

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

Typeahead和screenreaders

我正在使用Typeahead/Bloodhound从数据库的内容生成列表.我希望屏幕阅读器在突出显示时能够阅读血腥建议.我在元素中添加了一些咏叹调角色,试图从屏幕阅读器中读取内容.但是,突出显示时,屏幕阅读器是静音的.如果我将焦点添加到元素,那么blodhound模态窗口将关闭,这将无法正常工作.

到目前为止我所拥有的:

 var myTypeahead = $('.supersearch').typeahead({
      highlight: true,
      autoselect: true
 },
 {
      name: 'search-content',
      displayKey: 'title',
      source: content.ttAdapter(),
      templates:{
           header: '<h3 class="typeaheadTitle">Filtering Content...</h3>',
           empty: [
                '<div class="noResults">',
                'No Results',
                '</div>'
           ].join('\n'),
           suggestion: Handlebars.compile('<div class="searchListItem"><a href="{{link}}" class="searchLink" aria-label="{{title}}">{{title}}</a></div>')
      }
 });


 myTypeahead.on('typeahead:cursorchanged', function($e, datum){
      $(this).html(datum["value"]);
      var focused = $( document.activeElement )
      var submenuHighlight = focused.parent().find('.tt-cursor .searchListItem a');
      console.log(submenuHighlight.text());
 });

 // Add aria dialog role
 $('.tt-dataset-search-content').attr({
      'role': 'dialog',
      'aria-live': 'assertive',
      'aria-relevant':'additions'
 });
Run Code Online (Sandbox Code Playgroud)

这会将aria标签角色添加到输出列表和容器,但尝试通知读者此列表动态更改.我也在听cursorchanged,所以我可以隔离我需要的元素(console.log验证这个),但我不知道如何告诉读者用tt-cursor类读取当前项.

这是HTML输出:

 <div class="tt-dataset-search-content" role="dialog" aria-live="rude" aria-relevant="additions">
      <h3 class="typeaheadTitle">Filtering Content...</h3>
      <span …
Run Code Online (Sandbox Code Playgroud)

jquery accessibility screen-readers typeahead.js bloodhound

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

如何获取存储在开放层变量中的鼠标坐标?

我有一个代码可以在 openlayers 中显示地图之外的鼠标位置!如果我想在调用 js 鼠标事件 onmousedown 和 onmouseup 时保存这些坐标怎么办?

我有以下代码:

const mousePositionControl = new MousePosition({
    coordinateFormat: createStringXY(4),
    projection: 'EPSG:4326',
    className: 'custom-mouse-position',
    target: document.getElementById('mouse-position'),
    undefinedHTML: '&nbsp;'
});

const map = new Map({
    controls: defaultControls({
        attributionOptions: {
            collapsible: false
        }
    }).extend([mousePositionControl]),
    layers: [
        new TileLayer({
            source: new OSM()
        })
    ],
    target: 'map',
    view: new View({
        center: [0, 0],
        zoom: 2
    })
});
Run Code Online (Sandbox Code Playgroud)

javascript openlayers

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

仅在文本时如何访问ng-content值?

我试图访问的值span由下式给出其值ng-content

我在模板中有一个包含此html的按钮组件:

<span #text class="o-button-label">
    <ng-content></ng-content>
</span>
Run Code Online (Sandbox Code Playgroud)

所以我可以

<my-button>Hello</my-button>
Run Code Online (Sandbox Code Playgroud)

转变为

<span #text class="o-button-label">
    Hello
</span>
Run Code Online (Sandbox Code Playgroud)

现在,我希望该文本能够在.NET中也能使用aria-label。除其他外,我在my-button组件中尝试了以下操作:

@ViewChild('text') textElement: ElementRef;
ngAfterViewInit() {
    console.log('textElement', this.textElement.nativeElement.value);
}
Run Code Online (Sandbox Code Playgroud)

但这总是给我undefinedvaluenodeValue退货代替null。我检查了this.textElement.nativeElement哪个是span预期的,span包含预期的值,但是我找不到找到该文本值的方法。

我所做的所有搜索都指向与我一样的用法@ViewChild,但是总是要获取一些组件或DOM节点(例如在这个好主题中),而不仅仅是获取文本,因此是否有可能获取由注入的文本值ng-content

angular

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

React Big Calendar如何在月视图中设置一天的样式

因此,如图所示,我想对单个事件进行样式设置。

外观示例

使用slotpropgetter可以有条件地渲染样式。

slotPropGetter = date => {
    const CURRENT_DATE = moment().toDate();
    let backgroundColor;

    if (moment(date).isBefore(CURRENT_DATE, "month")) {
        backgroundColor = "#f7f8f9";
    }

    var style = {
        backgroundColor
    };
    return {
        style: style
    };
};
Run Code Online (Sandbox Code Playgroud)

因此,“解决方案”是DateCellWrapper,它要么对我不起作用,要么我以错误的方式实现了它

const DateCellWrapper = ({ value, children }) => {
    console.log("DateCellWrapper")
    const style = {
        backgroundColor: "#000",
    };

    return (
        <div style={style}>{children}</div>
    );
}
Run Code Online (Sandbox Code Playgroud)

它甚至不输出我的console.log,所以..有人知道吗?:p

javascript css reactjs react-big-calendar

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

将引导程序迁移到v4 - 弹出窗口无法正常工作

我有从将版本3迁移到4的Bootstrap的问题.问题在于popovers和popper.js库.每次我在一个元素上悬停我都会收到此错误:

未捕获的TypeError:无法读取未定义的属性'indexOf'

at v(computeAutoPlacement.js:24)at.onLoad(applyStyle.js:57)at index.js:69 at Array.forEach()at new t(index.js:67)atthehow(tooltip.js:286) )在HTMLSpanElement.(popover.js:166)在函数each(jquery.min.js:2)at r.fn.init.each(jquery.min.js:2)at r.fn.init.i._jQueryInterface [as popover ](popover.js:149)

在此输入图像描述

我使用的库:

<script src="https://code.jquery.com/jquery-3.2.1.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.1/js/bootstrap.min.js"></script>
Run Code Online (Sandbox Code Playgroud)

和Angular 1.6

这就是元素的样子:

<span class="tip-icon m-r-0" data-toggle="popover" data-content{{item.info}}" ng-if="item.info">Tooltip</span>
Run Code Online (Sandbox Code Playgroud)

这就是它在控制器中的设置方式:

$('[data-toggle="popover"]').popover({
    trigger: 'hover',
    animation: false,
    html: true
});
Run Code Online (Sandbox Code Playgroud)

当我迁移回Bootstrap 2.3.2时,一切正常.

是什么导致问题?先感谢您!

javascript popover twitter-bootstrap angularjs bootstrap-4

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

剑道复选框勾选事件

我试图捕捉剑道复选框事件,但我无法让它工作。我确定我错过了一些东西。在这个简单的事情上花了一个多小时,我很累。以下是代码片段。

HTML

<div class="bottomPadding row">
    <div class="col-md-4 col-sm-4 col-xs-12 col">
        <label>Send Activation Link</label>
    </div>
    <div class="col-md-6 col-sm-6 col-xs-12 col">
        <input id="sendLink" type="checkbox" data-bind="checked: Account.IsLink" />
    </div>
</div>
Run Code Online (Sandbox Code Playgroud)

和 JS 代码,

$("#sendLink").click(function () {
    if (this.checked) {
        console.log("hit");
    }
});
Run Code Online (Sandbox Code Playgroud)

请纠正我哪里搞砸了。

PS:我提到了几个 SO 答案,有些没有答案,有些答案在我的情况下不起作用。

javascript checkbox events kendo-ui

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

仅在 div 容器内固定位置元素

我在容器中有一个固定的块元素。滚动时,固定定位的元素超出了容器。我知道固定元素将根据窗口 vw 定位。但是有什么方法可以确保固定定位的元素只会滚动到容器位置。固定位置元素不应超出容器

问题如下所示。

https://codepen.io/anon/pen/dKLByX

我尝试使用以下方法解决问题:

if($(window).scrollTop()>1900){
    $('.fixed-ct').css({'bottom':'200px','top':'auto'});
}else if($(document).scrollTop() <=100) {
    $('.fixed-ct').css({'top':'10px','bottom':'auto'});
}else {
    $('.fixed-ct').css({'top':'0px','bottom':'auto'});
}
Run Code Online (Sandbox Code Playgroud)

但有时固定容器在末尾,因为底部 200px 它应该在顶部使用 top:0px 滚动并且它应该在容器本身内部。

html css jquery scroll css-position

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