如何使用数据存储在 Sencha Touch 中设置工具栏标题

发布于 2024-11-29 18:50:26 字数 343 浏览 3 评论 0原文

我正在尝试动态设置工具栏项。到目前为止,我有一个后退按钮,如果用户选择返回,则可以将工具栏标题重置为“开始”。

但以下代码不起作用:

menuList.on('itemtap', function(dataView, index, item, e){
     viewport.dockedItems.items[0].setTitle('{title}');
});

它尝试使用我的数据存储数组中名为“title”的变量。这非常适合向我的 Ext.List 项目提供文本。但上面的代码将工具栏标题设置为字符串“{title}”,甚至没有将其视为变量。

你能帮我一下吗?

I am trying to set the toolbar item dynamically. So far I have a back button that resets the toolbar title to 'start' if the user chooses to go back.

But the following code won't work:

menuList.on('itemtap', function(dataView, index, item, e){
     viewport.dockedItems.items[0].setTitle('{title}');
});

It tries to use a variable called 'title' out of my data store array. This works great for providing text to my Ext.List items. But the above code sets the toolbar title to the string '{title}' without even thinking of it being a variable.

Can you help me out?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

孤者何惧 2024-12-06 18:50:26

列表使用模板,以便对大括号内的项目进行评估...您需要传递对不带引号的变量的引用。您没有提供足够的代码让我告诉您该信息在哪里。如果您在范围内已经有一个名为 title 的变量,您可以将数据放入其中,那么您只需删除“{ 和 }”...否则您需要通过某种方式从商店获取所需的数据,例如 Ext .StoreMgr 或 [应用程序名称].stores

List's use templates so items within curley braces get evaluated... you'll need to pass a reference to a variable without quotes. You haven't provided enough code for me to tell you where that information would be. If you already have a variable in scope called title that you put the data into then you can just reamove the '{ and }' ... otherwise you'll need to get the data you need from your store through some means, like Ext.StoreMgr or [appname].stores

我最亲爱的 2024-12-06 18:50:26

有两件事。 1) 你真的很想习惯深入研究 ST 源代码。在这种情况下,如果您查看“setTitle”的代码,您将看到它的参数被解释为直接 HTML,而不是模板。所以这里不能使用大括号语法。 2) 请注意,事件处理程序的“item”参数的类型是一个 Element(即 DOM 对象的 ST 表示,而不是选定的数据存储对象。所以这对您没有帮助。但是,“index”参数给出您可以轻松地从商店获取合适的物品。

[appname].stores.pages.getAt(index).title

Two things. 1) You will really want to get used to digging into the ST source code. In this case, if you look at the code for "setTitle", you will see that its argument is interpreted as straight HTML, not a template. So you can't use curly bracket syntax here. 2) Note that the type of the "item" argument to the event handler is an Element (i.e. ST's representation of the DOM object, not the selected datastore object. So that's not going to help you. However, the "index" arg gives you an easy way to get the appropriate object from the store. i.e.

[appname].stores.pages.getAt(index).title
奢欲 2024-12-06 18:50:26

我真的不知道为什么,但如果你输入变量,它就会起作用:一个用于记录,一个用于该记录内的值。 sencha 中有详细说明。 com论坛

I really don't know why, but it works if you put up to variables: One for the record and one for the value inside that record. There is a detailed explanation in the sencha.com-forum

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文