小编Sen*_*mas的帖子

在Angular中删除或添加Class

我有一个列表和dragula我使用的插件()在某些操作上添加了某些css类.我正在使用Angular5.我想找出某些class(myClass)的存在并删除它并替换为(yourClass).在jquery中,我们可以这样做

$( "p" ).removeClass( "myClass" ).addClass( "yourClass" );
Run Code Online (Sandbox Code Playgroud)

我怎样才能在Angular5中实现这个目标.这里的主要问题是myClass自动添加到li插件所选的内容中.所以使用函数我不能设置类.

当我尝试使用renderer2时,它正在删除css类并添加另一个类.但它只是增加了第一个李.我的代码是

let myTag ; 
myTag = this.el.nativeElement.querySelector("li");
this.renderer.addClass(myTag, 'gu-mirrorss')
this.renderer.removeClass(myTag, 'dragbox');

`<div  class="right-height" id ='dest' [dragula]='"second-bag"' [dragulaModel]="questions"> 
       {{ questions.length == 0 ? ' Drag and drop questions here ' : ' '}}
       <li #vc  data-toggle="tooltip" data-placement="bottom" title= {{question.questionSentence}} class="well dragbox"  *ngFor="let question of questions; let i = index" [attr.data-id]="question.questionId" [attr.data-index]="i" (click)="addThisQuestionToArray(question,i, $event)" [class.active]="isQuestionSelected(question)"  #myId > {{question.questionId}} {{question.questionSentence}}</li>
</div>`
Run Code Online (Sandbox Code Playgroud)

css typescript angular

5
推荐指数
3
解决办法
9591
查看次数

在Java中获取JSON字符串JsonNode中的所有键

我有一个json字符串,我需要验证并找到除json字符串中的列表以外的其他任何键。样本json字符串是

{
   "required" : true,
   "requiredMsg" : "Title needed",
   "choices" : [ "a", "b", "c", "d" ],
   "choiceSettings" : {
          "a" : {
          "exc" : true
      },
  "b" : { },
  "c" : { },
  "d" : {
  "textbox" : {
    "required" : true
  }
 }
},
"Settings" : {
"type" : "none"
}
}
Run Code Online (Sandbox Code Playgroud)

为了只允许预定义的键存在于json字符串中,我想获取json字符串中的所有键。如何获取json字符串中的所有键。我正在使用jsonNode。到目前为止,我的代码是

        JsonNode rootNode = mapper.readTree(option);
        JsonNode reqiredMessage = rootNode.path("reqiredMessage");             
        System.out.println("msg   : "+  reqiredMessage.asText());            
        JsonNode drNode = rootNode.path("choices");
        Iterator<JsonNode> itr = drNode.iterator();
        System.out.println("\nchoices:");
        while (itr.hasNext()) { …
Run Code Online (Sandbox Code Playgroud)

java json jackson

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

当浏览器关闭时清除本地存储

我创建了一个angular 5应用程序。这是使用基于令牌的系统。当前我将令牌存储在本地存储中。我希望在关闭浏览器时清除本地存储。并在浏览器刷新时不清除本地存储。之所以不使用sesionstorage,是因为在新标签页或窗口中打开页面会导致新会话的启动。我该如何使用app.component中的这段代码尝试

@HostListener('window:beforeunload', ['$event'])
  beforeunloadHandler(event) {
  alert("KKk")
  localStorage.removeItem('authToken');
}
Run Code Online (Sandbox Code Playgroud)

但是当浏览器关闭时并不会触发。实现此用例的最佳方法是什么。如果使用令牌,是否使用cookie存储是一个好方法

local-storage angular

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

标签 统计

angular ×2

css ×1

jackson ×1

java ×1

json ×1

local-storage ×1

typescript ×1