Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dynamic td width while creating table #1439

Closed
amirzandi opened this issue Apr 23, 2018 · 7 comments
Closed

Dynamic td width while creating table #1439

amirzandi opened this issue Apr 23, 2018 · 7 comments

Comments

@amirzandi
Copy link

amirzandi commented Apr 23, 2018

I am creating a table which includes two rows with dynamic numbers of td.
The important part is to set the width for each td and the width has been calculated and passed to view.
tdWidth: 100/numberOfChars => which gives a percentage for width
I am using following code but it is not working:

<table>
<tbody>
<tr>
{{#each array}}
<td style='width: {{tdWidth}}%;'>{{this}}</td>
{{/each}}
</tr>
</tbody>
</table>

any helps appreciated.

@amirzandi
Copy link
Author

@nknapp please help!

@magikstm
Copy link

What issue are you currently having?

More code would be needed to help resolve the issue.

@amirzandi
Copy link
Author

@magikstm actually tdWidth comes from server but it is not being rendered in client. while I check the source on client, it shows:

c but when I display tdWidth inside a span or div, it shows: 9.99 which means data is coming from server. It is not working while I place it inside the style tag of an element.

@magikstm
Copy link

@amirzandi could you please share more of your code?

Especially the part that creates the "tdWidth" value as well as how you link it to that part of your page.

@amirzandi
Copy link
Author

amirzandi commented Apr 24, 2018

@magikstm
this is the server side:
res.render('./game/phrase_box', {
layout: false,
incorrects: result.incorrects,
corrects: result.corrects,
numberOfChars: result.numberOfChars,
tdWidth: 100 / numberOfChars
});

this is the client side:
{{#if incorrects}}
{{#if corrects}}


            <tr>
                {{#each corrects}}
                    <td style="width:{{tdWidth}}%">{{this}}</td>
                {{/each}}
            </tr>
        </tbody>
    </table>
{{/if}}

{{else}}

{{/if}}

@magikstm
Copy link

You're iterating in "corrects" in your "each" statement, but that object doesn't hold the "tdWidth" object.

I think you may need to change this:
{{tdWidth}}

To this:
{{../tdWidth}}

Ref: http://handlebarsjs.com/ (under "Handlebars Paths")

@amirzandi
Copy link
Author

@magikstm ohhhhh you saved my day.... thank you very much... thanks a lot.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants