1

As a step to learn extjs, I am trying to design Sudoku game which has 81 blocks in it. To create 81 blocks, should I need to repeat the below code 81 times? or is there any way to dynamically create 81 blocks inside a single parent block?

//inside parent container
{
    xtype: 'container',
    border: 1,
    height: 30,
    style: {borderColor:'#565656', borderStyle:'solid', borderWidth:'1px'}  
}

I tried making it in to a function and call it in for loop for 81 times but this failed with many console errors in chrome with no result. I am using Sencha extjs 4.1.1a.

Here is my complete code:

Ext.onReady(function(){
  Ext.create('Ext.container.Container', {
    layout: {
        type: 'column'
    },
    width: 400,
    renderTo: Ext.getBody(),
    border: 1,
     height: 300,
    style: {borderColor:'#000000', borderStyle:'solid', borderWidth:'1px'},
    defaults: {
        width: 50
    },
    items: [{
        xtype: 'container',
        border: 1,
        height: 30,
        style: {borderColor:'#565656', borderStyle:'solid', borderWidth:'1px'}
    }]
  });
});

1 Answer 1

2

Items is just an array, so build the array dynamically:

var i = 0,
    items = [];

for (i = 0; i < 5; ++i) {
    items.push({
        html: 'Foo' + i
    });
}

new Ext.container.Container({
    renderTo: document.body,
    items: items
});
Sign up to request clarification or add additional context in comments.

2 Comments

Thank you.. this did the work. :) One small doubt, how to give position absolute and relative just like in css using extjs..?
I got it.. just use style property :D

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.