joh*_*rds 10 javascript extjs sencha-touch
我正在采取Sencha touch的第一步.结果正是我所追求的,然而到达那里却很难得到如何将sencha放在一起.我正在慢慢搞清楚,但有时代码的工作方式有点WTF.
我正在尝试构建一个非常简单的应用程序,执行以下操作.
1)有三个选项卡,搜索附近(地理位置),快速关键字搜索,类别搜索.
2)每个选项卡搜索返回结果列表
3)每个行都可以单击以显示更多信息.
我已经想出了我认为的标签.
像这样:
Ext.setup({
tabletStartupScreen: 'tablet_startup.png',
phoneStartupScreen: 'phone_startup.png',
icon: 'icon.png',
glossOnIcon: false,
onReady: function() {
var location = new Ext.Container({
iconCls: 'search',
title: 'Location Search',
items: [new Ext.Component({
html: '<img src="images/gfb.gif" />'
})]
});
var quick = new Ext.Container({
iconCls: 'search',
title: 'Quick Search',
scroll: 'vertical',
items: [new Ext.Component({
html: '<img src="images/gfb.gif" />'
})]
});
var category = new Ext.Component({
iconCls: 'search',
title: 'Category Search',
html: '<img src="images/gfb.gif" /><p>Category</p>'
});
var tabpanel = new Ext.TabPanel({
fullscreen: true,
tabBar: {
dock: 'bottom',
scroll: 'horizontal',
sortable: false,
layout: {
pack: 'center'
}
},
cls: 'card1',
items: [
location,
quick,
category
]
});
}
});
Run Code Online (Sandbox Code Playgroud)
这很好用.我知道的标签之间没有区别,但我正在建立...
是的,我想要处理的第一件事是关键字搜索选项卡,因为这是测试此应用程序最简单的选项.
所以我添加了一个表单.
var quickFormBase = {
url: "../quicksearch.php?output=json",
items: [{
xtype: 'fieldset',
instructions: 'The keyword search is great if you know the name of the company you are looking for, or the particular service you need to find.<p><br />To narrow it down to an area include the town or county name in your query</p>',
defaults: {
required: false,
labelAlign: 'left'
},
items: [{
xtype: 'textfield',
label: 'Search',
name : 'inpquery',
showClear: true,
autoCapitalize : false
}]
}],
listeners : {
submit : function(form, result){
console.log('results', result.SearchResults.MainResults.Advert);
},
exception : function(form, result){
console.log('failure', Ext.toArray(arguments));
}
}
};
var quickForm = new Ext.form.FormPanel(quickFormBase);
Run Code Online (Sandbox Code Playgroud)
所以我的快速标签配置现在看起来像这样:
var quick = new Ext.Container({
iconCls: 'search',
title: 'Quick Search',
scroll: 'vertical',
items: [new Ext.Component({
html: '<img src="images/gfb.gif" />'
}),quickForm]
});
Run Code Online (Sandbox Code Playgroud)
我现在有一个表格,看看我想要的内容,并挂钩到我的json搜索并将广告返回到控制台.大!
现在我想创建一个列表视图,其顶部栏带有后退按钮.我很确定这不是设置它的方法,但我真的很难找到如何做到这一点的例子,因为源代码的示例有一个复杂的设置,而简单的那些不做我以后做的事情.
我现在在index.js文件的顶部添加一个模型配置来定义我的广告模型
Ext.regModel('Advert',{
fields: [
{name: 'advertid', type:'int'},
{name: 'Clientname', type:'string'},
{name: 'telephone', type:'string'},
{name: 'mobile', type:'string'},
{name: 'fax', type:'string'},
{name: 'url', type:'string'},
{name: 'email', type:'string'},
{name: 'additionalinfo', type:'string'},
{name: 'address1', type:'string'},
{name: 'address2', type:'string'},
{name: 'address3', type:'string'},
{name: 'postcode', type:'string'},
{name: 'city', type:'string'},
{name: 'Countyname', type:'string'},
{name: 'longitude', type:'string'},
{name: 'latitude', type:'string'}
]
});
Run Code Online (Sandbox Code Playgroud)
在我的表单成功听众中,我执行以下操作:
listeners : {
submit : function(form, result){
var quickstore = new Ext.data.JsonStore({
model : 'Advert',
data : result.SearchResults.MainResults.Advert
});
var listConfig = {
tpl: '<tpl for="."><div class="advert">{Clientname}</div></tpl>',
scope: this,
itemSelector: 'div.advert',
singleSelect: true,
store: quickstore,
dockedItems: [
{
xtype: 'toolbar',
dock: 'top',
items: [
{
text: 'Back',
ui: 'back',
handler: function(){
//Do some magic and make it go back, ta!
}
}
]
}
]
};
var list = new Ext.List(Ext.apply(listConfig, {
fullscreen: true
}));
},
exception : function(form, result){
console.log('failure', Ext.toArray(arguments));
}
}
Run Code Online (Sandbox Code Playgroud)
但是它可以按照我的意愿滑入,就像点击底部标签栏中的图标一样.
现在这是我倒下的地方,我无法弄清楚我如何使后退按钮工作,让我回到关键字搜索.
我找到了setCard和setActiveItem,但我似乎无法在结果监听器函数中访问"this"上下文中的那些.
有人可以给出一个如何做到这一点的简单例子吗?
小智 12
解决这个问题的最简单方法可能是给你的TabPanel一个id,然后在你的处理程序中引用它.尝试更新您的tabpanel,如下所示:
var tabpanel = new Ext.TabPanel({
id: 'mainPanel',
... the rest of your config here
Run Code Online (Sandbox Code Playgroud)
你的后退按钮处理程序如下:
handler: function() {
Ext.getCmp('mainPanel').layout.setActiveItem(0);
}
Run Code Online (Sandbox Code Playgroud)
这将移至tabpanel中的第一张卡(您的位置卡).
或者,如果要在处理函数中修改'this'的值,则只需传入作用域:
text: 'Back',
ui: 'back',
scope: tabpanel,
handler: function(){
this.layout.setActiveItem(0);
}
Run Code Online (Sandbox Code Playgroud)
'this'现在指的是你在范围配置中传入的任何内容.看到人们使用"scope:this"是很常见的,因此处理程序中的"this"与处理程序外部的"this"相同.
| 归档时间: |
|
| 查看次数: |
13134 次 |
| 最近记录: |