最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to set html to a element in extjs - Stack Overflow

programmeradmin0浏览0评论

1) How to set HTML to already created panel or any other Element?

I am a beginner. I tried the below to set some content inside the HTML

var clickedElement = Ext.getCmp('id').el.child('>');
clickedElement.setHTML("hello");

The above is working fine but the problem is that as the panel has many div's inside it.. the above approach is erasing those inside html (i.e div's) and replacing it with the above content.

I saw through Chrome that the panel has three nested div's. So, if I want to add HTML to it then I need to give something like below:

var clickedElement = Ext.getCmp('id').el.child('>').child('>');  //two times child

When I tried the above approach, I am successfully adding the html content and also the div's doesn't remove. Here the problem is that, I can't see the added content (maybe because of some default stylings, I can see the content is being added in Chrome console though.)

I am just asking whether there is any efficient way of adding HTML to the panel. In my opinion, this should be very easy approach which I am complexing here.

2) How to check whether a Element has a particular child ?

Suppose, for example, If I added a extjs Button as a child(item) into my panel while creating it. (which I can do). How to check whether the panel has the particular element (i.e button here)?

Before asking here, I searched alot and found somewhat relative but not helpful link to my problem.

1) How to set HTML to already created panel or any other Element?

I am a beginner. I tried the below to set some content inside the HTML

var clickedElement = Ext.getCmp('id').el.child('>');
clickedElement.setHTML("hello");

The above is working fine but the problem is that as the panel has many div's inside it.. the above approach is erasing those inside html (i.e div's) and replacing it with the above content.

I saw through Chrome that the panel has three nested div's. So, if I want to add HTML to it then I need to give something like below:

var clickedElement = Ext.getCmp('id').el.child('>').child('>');  //two times child

When I tried the above approach, I am successfully adding the html content and also the div's doesn't remove. Here the problem is that, I can't see the added content (maybe because of some default stylings, I can see the content is being added in Chrome console though.)

I am just asking whether there is any efficient way of adding HTML to the panel. In my opinion, this should be very easy approach which I am complexing here.

2) How to check whether a Element has a particular child ?

Suppose, for example, If I added a extjs Button as a child(item) into my panel while creating it. (which I can do). How to check whether the panel has the particular element (i.e button here)?

Before asking here, I searched alot and found somewhat relative but not helpful link to my problem.

Share Improve this question edited May 23, 2017 at 12:22 CommunityBot 11 silver badge asked Feb 7, 2013 at 7:18 Mr_GreenMr_Green 41.8k47 gold badges170 silver badges276 bronze badges
Add a comment  | 

2 Answers 2

Reset to default 14

In ExtJS most components are considered to have only one body element even if you see more on the dom. In contrast to jQuery which is basically added above a markup ExtJS generate the whole markup by itself.

Now to your question, to update the HTML of a component you can simply call the update() method like that

Ext.getCmp('id').update('hello');

See JSFiddle

Ext.ComponentQuery.query('#itemIdOfComponent').update('new value');

Do not set id's on components instead add an itemId configuration and see the documentation for Ext.ComponentQuery.query.

发布评论

评论列表(0)

  1. 暂无评论