在 XTemplate 中包含 Sencha 组件
我正在开发一个 Sencha Touch 应用程序,在其中执行大量 Ext.extend 操作并创建自己的自定义组件和类。我对 Sencha Touch 领域比较陌生,并且在尝试在 Ext.XTemplate
中使用我的组件之一时遇到了一些问题。这是我试图在某些代码中执行的操作的概念:
MyObj = Ext.extend(Ext.Panel, {
cls: 'myClass',
layout: 'card',
scroll: 'vertical',
monitorOrientation: true,
config: myConfigObject.localObjectType,
loc: 'en_US',
initComponent: function() {
// some random init code here…
// Including:
var tpl = new Ext.XTemplate(
'<tpl for=".">',
'<tpl if="Available === true"><div class="itemAvail"></tpl>',
'<tpl if="Available !== true"><div class="itemNotAvail"></tpl>',
'<div class="formText">',
// INSERT MY VIDEO COMPONENT HERE…
'</div>',
'</div>',
'</tpl>',
{ compiled : true }
);
},
// Object definition continues, but I don't think it's germane to this discussion…
});
Ext.reg('videoList', MyApp.views.VideoList);
现在我需要在上面包含我的视频组件的半代码:
MyVideoComponent = Ext.extend(Ext.Panel, {
programID: null,
chapterID: null,
video: null,
videoPlayer: null,
initComponent: function() {
var progID = this.programID;
var chapID = this.chapterID;
// Set up the video object based on progID and chapID
this.videoPlayer = new Ext.Video({
id: "videoPlayer",
url: video.URL,
posterURL: video.posterURL,
fullscreen: true,
autoResume: true,
// configure listeners for play/end/error
});
// Call superclass.initComponent()
},
// Create listener callbacks for onPlay, onEnded, onError…
});
Ext.reg('videoComponent', MyApp.components.VideoComponent);
有人对如何实现此目标有任何想法吗?
谢谢!
I'm developing a Sencha Touch application in which I'm doing lots of Ext.extend
and creating my own custom components and classes. I'm relatively new to the Sencha Touch realm, and I'm having a bit of a problem trying to use one of my components inside an Ext.XTemplate
. Here's a concept of what I'm trying to do in some code:
MyObj = Ext.extend(Ext.Panel, {
cls: 'myClass',
layout: 'card',
scroll: 'vertical',
monitorOrientation: true,
config: myConfigObject.localObjectType,
loc: 'en_US',
initComponent: function() {
// some random init code here…
// Including:
var tpl = new Ext.XTemplate(
'<tpl for=".">',
'<tpl if="Available === true"><div class="itemAvail"></tpl>',
'<tpl if="Available !== true"><div class="itemNotAvail"></tpl>',
'<div class="formText">',
// INSERT MY VIDEO COMPONENT HERE…
'</div>',
'</div>',
'</tpl>',
{ compiled : true }
);
},
// Object definition continues, but I don't think it's germane to this discussion…
});
Ext.reg('videoList', MyApp.views.VideoList);
And now the semi-code for my Video Component that I need included above:
MyVideoComponent = Ext.extend(Ext.Panel, {
programID: null,
chapterID: null,
video: null,
videoPlayer: null,
initComponent: function() {
var progID = this.programID;
var chapID = this.chapterID;
// Set up the video object based on progID and chapID
this.videoPlayer = new Ext.Video({
id: "videoPlayer",
url: video.URL,
posterURL: video.posterURL,
fullscreen: true,
autoResume: true,
// configure listeners for play/end/error
});
// Call superclass.initComponent()
},
// Create listener callbacks for onPlay, onEnded, onError…
});
Ext.reg('videoComponent', MyApp.components.VideoComponent);
Does anyone have any ideas on how I can accomplish this?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
[Sencha Person] 我们的模板语言目前有点限制。一旦放入项目渲染器的 HTML 中,您就无法返回到组件级别。您可以通过将 panel 扩展为自定义组件来实现所需的结果,该组件迭代数据列表并创建项目并将其添加到 DOM。
我们希望使我们的模板更加灵活,以便您可以更轻松地完成您想要做的事情,但至少在 Touch 1.0 中,这不是一项基本任务。
[Sencha Person] Our template language currently is a bit restrictive. Once you drop into HTML for an item renderer, you cannot get back to the component level. You can achieve the desired result by extending panel as a custom component that iterates through a data list and creates and adds the items to the DOM.
We'd like to make our templating much more flexible so you can accomplish what you're looking to do more easily, but at least in Touch 1.0, it's not a basic task.
由于您提供的代码非常概念化,我只能提供可能的解决方案的总体方向:
我会尝试将页面中的内容分解为多个组件,并使用 Sencha 提供的布局系统组织它们(包括视频组件)触碰。
使用 Extjs/Sencha Touch 时,考虑视图的“正确”方式不是用 html 编写它们,而是尽可能使用库中的组件来构造它们。
Since the code you presented is quite conceptual, I can only provide a general direction to possible solutions:
I would try to break down the content in the page into multiple components and organize them (including the video component) with the layout system provided by Sencha Touch.
When using Extjs/Sencha Touch, the "proper" way to think of views is not to write them in html, but to construct them with components in the library as much as possible.