Search code examples
javascriptextjssencha-touch

Segmented button with numeric value in Sencha Touch


I am working in a Sencha Touch application and I have a doubt with the next implementation, I have this code:

  {
    xtype: 'segmentedbutton',
    cls : 'filterbar-segmented-button',
    items: [
      {
        text: x.util.I18n.getLabel('CustomerHeaderAll'),
        pressed: true
      },
      {
        text: x.util.I18n.getLabel('CustomerHeaderWithSurvey')
      }
    ]
  }

I am getting the label from the backend but I need to get the total value.

here Json API:

"CustomerHeaderAll" : "All {0}",
"CustomerHeaderWithSurvey": "With Survey {0}",

How should I implement the value (in between brackets) in the view? Now only I am displaying the label, but I need to concatenate both.

Thanks a lot!!


Solution

  • Try tpl config in Ext.button and set data config as initial display.

    Call Ext.button.setData() to change displayed text.

    For example:

    {
        xtype: 'segmentedbutton',
        cls : 'filterbar-segmented-button',
        items: [
          {
            data: {textVal: 1},
            tpl: "All {textVal}",
            pressed: true
          },
          {
            data: {suveyVal: 1},
            tpl: "With Survey {suveyVal}"
          }
        ]
      }