Is there an example of setting and retrieving settings from a Rally SDK 2 app?

扶醉桌前 提交于 2019-12-13 15:18:04

问题


What does a settings object look like? I can't seem to updateSettings with anything and get something back interesting. I'm printing out this.settings and every time I refresh, it just logs a prototype object with no values.

This is what my test app looks like. I am putting it into a panel inside Rally, not running remotely.

<script type="text/javascript" src="/apps/2.0p2/sdk.js"></script>

<script type="text/javascript">
    Rally.onReady(function() {
        /*global console, Ext */

        Ext.define('CustomApp', {
            extend: 'Rally.app.App',
            componentCls: 'app',

            launch: function() {
                //Write app code here
                console.log( "settings", this.settings );
                this.updateSettings( { Name: 'test', Value: Ext.JSON.encode( { test: "blah" } ) } );
            }
        });

        Rally.launchApp('CustomApp', {
            name: 'test'
        });
    });
</script>

回答1:


Turns out there is a bug in the preview version I was using. And I was trying to pass the wrong kind of preference. Note that preferences are scoped to the App ID and not to the project or workspace. Since it needs the app's ID, it doesn't work when run outside Rally.

The bug is that the updateSettings function is missing a line. You can easily override this by adding the same function to your app definition (isn't it neat that the source is included in the docs?) Just make a function like this:

updateSettings: function(options){
  Rally.data.PreferenceManager.updateAppPreferences({
    appID: this.getContext().get('appID'),
    settings: options.settings,
    success: function(updatedSettings){
      Ext.apply(this.settings, updatedSettings);
      if(options.success){
        options.success.call(options.scope);
      }
    },
    scope: this
  });
}

So, then, the preference object should be passed like this:

this.updateSettings( {settings: { test: "blah" ) } } );

Then, when it comes back, the getSetting("test") will give me "blah". (It creates a preference with Name equal to "test", Value equal to "blah" and an AppId equal to the current app.



来源:https://stackoverflow.com/questions/11680816/is-there-an-example-of-setting-and-retrieving-settings-from-a-rally-sdk-2-app

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