'setProgress not a function' error while setting progress value of a progress bar

懵懂的女人 提交于 2019-12-12 02:35:42

问题


I want to set value of a progress bar in an accordian but I am encountering 'setProgress is not a function' error. Any idea what's wrong with following code.

Observation: If I move the progress bar out of the Accordian then the error goes away and the progress bar appears fine.

I want to set the progress bar eventually to {repMonitor.currentItem.threatLevel} but for now I am just testing with hypothetical threat value i.e 60

<mx:Accordion id="monAccordian" includeIn="Monitoring" x="10" y="10" width="554" height="242" change="monAccordianChange()" >       
   <mx:Repeater id="repMonitor" dataProvider="{monitoringArray}">
      <mx:Canvas width="100%" height="100%" label="{repMonitor.currentItem.firstName+' '+ repMonitor.currentItem.lastName}" >
        <mx:Image x="10" y="10" source="{repMonitor.currentItem.imageName}" width="175" height="118"/>
        <s:Label x="200" y="14" text="Threat Level:"/>
          <mx:ProgressBar x="200" y="30" mode="manual" label="" id="bar" width="200" creationComplete="bar.setProgress(60,100);" />
      </mx:Canvas>
   </mx:Repeater>
</mx:Accordion>

回答1:


This stems from the fact that your ProgressBar is in a repeater. You cannot reference the repeated items by id because you would have a variable number of ProgressBars with id "bar".

There are also special considerations when using event listeners inside of Repeater objects:

Event handlers in Repeater components

When a Repeater component is busy repeating, each repeated object that it creates can bind at that moment to the Repeater component's currentItem property, which is changing as the Repeater component repeats. You cannot give each instance its own event handler by writing something like click="doSomething({r.currentItem})" because binding expressions are not allowed in event handlers, and all instances of the repeated component must share the same event handler.

Repeated components and repeated Repeater components have a getRepeaterItem() method that returns the item in the dataProvider property that was used to produce the object. When the Repeater component finishes repeating, you can use the getRepeaterItem() method to determine what the event handler should do based on the currentItem property. To do so, you pass the event.currentTarget.getRepeaterItem() method to the event handler. The getRepeaterItem() method takes an optional index that specifies which Repeater components you want when nested Repeater components are present; the 0 index is the outermost Repeater component. If you do not specify the index argument, the innermost Repeater component is implied.

You can read more about this in the Repeater docs.



来源:https://stackoverflow.com/questions/5160887/setprogress-not-a-function-error-while-setting-progress-value-of-a-progress-ba

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!