3

I just want to read my data in an Object and print multiply buttons in a row.
How could I do that?

A similar example :

var obj={"coca":"2$" , "7up":"3$" , "fanta":"4$"} 
for (var key in obj) {
  if (obj.hasOwnProperty(key)) {
      ctx.reply('price list', Extra.HTML().markup((m) =>
        m.inlineKeyboard([
          [m.callbackButton(`${key} : `, ` price : ${obj[key]}`)]
        ]))))

But the problem is I do not want to print "price list" every time.
I just want to print it 1 times on top, and I can not use for loop inside "ctx.reply"

2
  • 2
    Why don't you add a break after first reply? Commented Sep 22, 2017 at 15:45
  • i do not want to break it , i need all buttons that created with m.inlinekeyboard , i just want to print price list 1 time Commented Sep 22, 2017 at 21:35

1 Answer 1

2

If you just want the first item to be replied, all you have to do is to break the loop after first reply.

Your code may be like this:

var obj={"coca":"2$" , "7up":"3$" , "fanta":"4$"} 
for (var key in obj) {
  if (obj.hasOwnProperty(key)) {
          ctx.reply('price list', Extra.HTML().markup((m) =>
          m.inlineKeyboard([
          [m.callbackButton(`${key} : `, ` price : ${obj[key]}`)]
        ]))));
  break;
  }
}
Sign up to request clarification or add additional context in comments.

1 Comment

i do not want to break it , i need all buttons that created with m.inlinekeyboard , i just want to print price list 1 time

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.