小编dev*_*033的帖子

角色="radiogroup"和角色="无线电"真的是必要的吗?

有一些ARIA教程网站使用非语义标记和一些JavaScript在于向世人证明使用role="radiogroup",并role="radio"如下面的例子:

<ul role="radiogroup">  
    <li tabindex="-1" role="radio" aria-checked="false">  
        <img role="presentation" src="radio-unchecked.gif">
        Option1
    </li>  
    <li tabindex="0"  role="radio" aria-checked="true">  
        <img role="presentation" src="radio-checked.gif">
        Option2
    </li>  
</ul>
Run Code Online (Sandbox Code Playgroud)


但是,role当我们已经拥有语义和无javascript方法时,使用这些方法有什么意义:

<ul>  
    <li>  
        <input  id="opt1" type="radio" name="opt" value="1">
        <label for="opt1">Option1</label>
    </li>  
    <li>  
        <input  id="opt2" type="radio" name="opt" value="2">
        <label for="opt2">Option2</label>
    </li>  
</ul>
Run Code Online (Sandbox Code Playgroud)

html radio wai-aria

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

替换特殊字符Ruby

我想替换所有这些字符:'àáäâãèéë?êìíïî?òóöôõùúüû?ñç'to 'aaaaaeeeeeiiiiiooooouuuuunc'.

有没有一种有效的方法在Ruby中执行此操作?我在考虑循环每个角色,但它没有效果.

谢谢.

ruby special-characters gsub

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

用零填充2D ArrayList

我知道我可以zeros使用以下语句填充正常的矢量商/列表:

double[][] list = new double[10][10]; // It will automatically inserts 0's in all positions.
List<Double> list1 = new ArrayList(new ArrayList(Collections.nCopies(10, 0d))); // Also
Run Code Online (Sandbox Code Playgroud)

我想做出同样的事情使用2D名单,这可能吗?

List<List<Double>> list2 = new ArrayList();
// It doesn't work -> List<List<Double>> list2 = new ArrayList(new ArrayList(Collections.nCopies(10, 0d)));
Run Code Online (Sandbox Code Playgroud)

顺便说一句,我想避免使用显式循环。

java collections arraylist

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

排序本机方法Java的问题

我正在尝试使用本机sort方法来排序元素.

码:

List<String> list = new ArrayList();
Collections.sort(list);
Run Code Online (Sandbox Code Playgroud)

输入1:

Before order: 65 31 37 37 72 76 61 35 57 37
After order:  31 35 37 37 37 57 61 65 72 76
Expected:     Ok.
Run Code Online (Sandbox Code Playgroud)

输入2:

Before order: 45 186 185 55 51 51 22 78 64 26 49 21
After order:  185 186 21 22 26 45 49 51 51 55 64 78
Expected:     21 22 26 45 49 51 51 55 64 78 185 186
Run Code Online (Sandbox Code Playgroud)

问题是该方法在某些情况下排序错误,我该如何解决?

java sorting collections

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

在Realm Android中添加初始数据

我正在使用领域,所有看起来都很好,直到我尝试在我的数据库中添加初始数据.

我在这个答案中遵循了这个例子,所以在我的课程中,继承自Application,我有以下内容:

public class MainApplication extends Application {
    @Override
    public void onCreate() {
        super.onCreate();
        Realm.init(this);
        final Map<String, String> map = new LinkedHashMap();
        map.put("Key1", "value1");
        map.put("Key2", "value2");
        RealmConfiguration config = new RealmConfiguration.Builder().initialData(new Realm.Transaction() {
            @Override
            public void execute(Realm realm) {
                int i = 1;
                for (Map.Entry entry : map.entrySet()) {
                    realm.beginTransaction();
                    Category c = realm.createObject(Category.class, i++);
                    c.setName((String) entry.getKey());
                    c.setDescription("Category #" + entry.getValue());
                    realm.commitTransaction();
                }
                realm.close();
            }
        }).deleteRealmIfMigrationNeeded().name("realm.db").build();
        Realm.setDefaultConfiguration(config);
    }
}
Run Code Online (Sandbox Code Playgroud)

我认为这种配置应该可行,但是我收到以下错误:

java.lang.IllegalStateException:Realm已经在/ path /中写入事务了...

有什么东西我不见了吗?

提前致谢.

java android realm

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

Angular:解析器错误:意外的标记 -、预期的标识符、关键字或字符串

我在我的项目中使用@angular~4.0.0,我以表格形式显示数据并想添加搜索控件。

该代码有效(没有过滤器)

<tr *ngFor="let item of components">
Run Code Online (Sandbox Code Playgroud)

但是当我为过滤器添加以下代码时,它会抛出错误

<tr *ngFor="let item of components | filter-data:compName">
Run Code Online (Sandbox Code Playgroud)

错误 :

Unhandled Promise rejection: Template parse errors:
TypeError: Unable to get property 'toUpperCase' of undefined or null reference ("
            </tr>
        </thead>
        <tr [ERROR ->]*ngFor="let item of components | filter-data:compName">
        <!--<tr *ngFor="let item of componen"): ng:///App/PortalComponents/ComponentList/component-list.component.html@14:12
Parser Error: Unexpected token -, expected identifier, keyword, or string at column 32 in [let item of components | filter-data:compName] in ng:///App/PortalComponents/ComponentList/component-list.component.html@14:12 ("nts | filter-data:compName">
        <!--<tr *ngFor="let item of …
Run Code Online (Sandbox Code Playgroud)

angular-pipe angular

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

在 ngSwitch 中使用 ng-template 参考

我不想html在每个*ngSwitchCase块中编写代码,而是想添加对 a 的引用ng-template (来自 angular docs):

<div *ngIf="show; then thenBlock; else elseBlock">this is ignored</div>
<ng-template #primaryBlock>Primary text to show</ng-template>
Run Code Online (Sandbox Code Playgroud)

想要这样做:

<div [ngSwitch]="switchVar">
  <div *ngSwitchCase="1; then myTemplate"></div>
  <div *ngSwitchDefault>output2</div>
</div>
<ng-template #myTemplate>HTML TEXT</ng-template>
Run Code Online (Sandbox Code Playgroud)

而不是这个:

<div [ngSwitch]="switchVar">
  <div *ngSwitchCase="1">HTML TEXT</div>
  <div *ngSwitchDefault>output2</div>
</div>
Run Code Online (Sandbox Code Playgroud)

angular

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

Angular 2.subscribe()返回undefined

在组件中,我称为dataservice方法'login',它调用post api.res.json()给出了正确的答案.但是在组件中,当我尝试访问"数据"时,它在订阅中未定义.不知道我在这里做错了什么.请帮忙.

dataService:

login(username, password): Observable<any>{       
    let data = { username: username, password: password};
    return this.http.post( this.domain + '/webservice/login', data)
                    .map( (res: Response) => {
                      res.json()                      
                    })
                    .catch( (error: any) => Observable.throw(error.json().error || 'server error') );

  }
Run Code Online (Sandbox Code Playgroud)

组件:

callLoginApi() {
    this.showLoading = true;
    this.dataService.login(this.username,this.password)
         .subscribe(data => {
              console.log(data);
          });
  }  
Run Code Online (Sandbox Code Playgroud)

angular

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

TypeScript:根据元组获取嵌套属性的类型

在 TypeScript 中,有没有一种方法可以根据某些元组获取嵌套属性的类型?给定以下示例,假设元组是["bs", 0, "c"],那么类型应该是boolean(或者["bs", 0, "ds", 0, "f"]等等number)。

interface Foo {
  a: string;
  bs: {
    c: boolean;
    ds: {
      e: null;
      f: number;
    }[];
  }[];
}
Run Code Online (Sandbox Code Playgroud)

对于某些上下文,我想输入一个带有两个参数 apath和 a 的函数value。对于某些对象,如果给定路径的值是一个数组,它将是push参数value。这个函数的实现可以在这个 Playround中找到。我已经在寻找一些解决方案,例如在本期中,但我认为我的问题有点不同。

typescript

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

Angular 2 - 如何自动将对象值绑定到与Form控件相关的值?

我正在使用model driven forms,我正在寻找一种更好的方法将数据绑定到相关的,formControlName因为我的表单上有超过25个字段,我不想为所有字段编写代码,因为我已经写了对于下面.

模板:

<input type="text"
       class="form-control"
       formControlName="firstName"
       name="firstName"
       placeholder="First Name"
       required>
Run Code Online (Sandbox Code Playgroud)

组件:

this.refferalService.getReferringDataEdit(id).subscribe(
  result => {
    this.referringData = result.responseObject;
    this.refferalForm.patchValue({ 
      firstName: this.referringData.firstName 
    })
  }
)
Run Code Online (Sandbox Code Playgroud)

有没有办法"自动"?

angular2-forms angular2-template angular2-formbuilder angular

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