有没有从Rally SDK 2应用程序设置和检索设置的示例? [英] Is there an example of setting and retrieving settings from a Rally SDK 2 app?

查看:87
本文介绍了有没有从Rally SDK 2应用程序设置和检索设置的示例?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

设置对象的外观如何?我似乎没有更新任何东西,并得到一些有趣的东西。我打印出这个设置,每次刷新时,它只记录一个没有值的原型对象。

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.

这是我的测试应用程序的样子。我把它放在Rally里面的一个面板里,不能远程运行。

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>


推荐答案

显示预览版本中有一个错误正在使用。 我试图通过错误的偏好。请注意,首选项的作用域为应用程序ID,而不是项目或工作空间。因为它需要应用程序的ID,所以在Rally之外运行时不起作用。

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.

错误是updateSettings函数缺少一行。您可以通过在应用程序定义中添加相同的功能来轻松地覆盖此内容(源文件不包含在文档中)?只需执行以下功能:

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" ) } } );

然后,当它回来时,getSetting(test)会给我blah。 (它创建一个名称等于测试的偏好,值等于blah,AppId等于当前的应用程序。

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.

这篇关于有没有从Rally SDK 2应用程序设置和检索设置的示例?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆