简体   繁体   English

更改图像或图标并重新粉刷

[英]sproutcore change image or icon and repaint

I want to change the icon/image in the statechart.js, that is display and hide it a number of times. 我想更改statechart.js中的图标/图像,即显示并隐藏它多次。 I tried a icon to a label and a extra childview. 我尝试了一个带有标签的图标和一个额外的childview。 Question: How to hide/change the icon/childview programmatically? 问题:如何以编程方式隐藏/更改图标/子视图?

With the extra childview I was abled to change the value, but this change is not visible on the screen. 通过额外的childview,我可以更改该值,但是此更改在屏幕上不可见。

    SC.LabelView.design icon: 'icon-heart',
    ..
    heart: SC.ImageView.extend({
                classNames: ['icon-heart'],
                  value: 'heart.png'
                }),

MyApp.mainPage.getPath('mainPane.navigationView.heart').value = 'icon-next';

SproutCore uses the observer pattern to know when values have changed. SproutCore使用观察者模式来知道何时值已更改。 In order for this to work, SproutCore requires that you use the set() and get() methods so that it will see the change and can update the display accordingly. 为了使它起作用,SproutCore要求您使用set()get()方法,以便它可以看到更改并可以相应地更新显示。

Try changing your last line to: 尝试将最后一行更改为:

MyApp.mainPage.getPath('mainPane.navigationView.heart').set('value', 'icon-next');

Also, you should definitely look at using Bindings to easily bind the value to a controller (or even a plain SC.Object for something this simple) and have your view watch for changes there. 另外,您绝对应该看一下使用Bindings轻松地将值绑定到控制器(甚至是简单的SC.Object绑定这个简单的东西),并让您的视图监视那里的更改。 Quick example: 快速示例:

myApp.myController = SC.Object.extend({
  iconValue: 'icon-heart'
})

myApp.myView = SC.ImageView.extend({
  valueBinding: SC.Binding.oneWay('myApp.myController.iconValue')
})

Now, later on, you can do the following from within your statechart: 现在,稍后,您可以在状态图中执行以下操作:

myApp.myController.set('iconValue', 'icon-next');

and the view should automatically update. 并且视图应自动更新。

Please post a comment if you run into issues and I'll do my best to help. 如果您遇到问题,请发表评论,我会尽力为您提供帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM