我正在玩sencha touch 2.0,我遇到以下問題。Sencha touch 2.0無法在視口上設置activeitem
我想在我的視口上設置activeitem,但根據我的調試控制檯該功能沒有被識別。是的,我的佈局=卡。
有人可以告訴我如何改變我的看法!
這裏是我的代碼
這是它GOED錯誤:
//這是哪裏出了問題
App.view.Viewport.setActiveItem("App.view.user.Index",{
type: "slide",
direction: "left"
});
我也嘗試
this.App.view.Viewport.setActiveItem("App.view.user.Index",{
type: "slide",
direction: "left"
});
但是,讓相同的錯誤:setActiveItem不存在:
如果需要210Uncaught TypeError: Object function() {
return this.constructor.apply(this, arguments);
} has no method 'setActiveItem'
的其餘代碼:App.js
Ext.Loader.setConfig(
{
enabled: true ,
paths:{
//set application path
App: 'app'
}
});
// Main application entry point
Ext.application({
name: 'App',
//Define all models and controllers in the application
//Views do not have to be defined these are defined in the controllers
//Models
//Controllers
controllers: ['User'],
//automatically create a viewport(template) instance/object app/Viewport.js
autoCreateViewport: true,
launch: function() {
}
});
視窗
Ext.define('App.view.Viewport', {
extend: 'Ext.viewport.Default',
xtype: "Viewport",
config: {
fullscreen:true,
layout: "card",
items:[
{
xtype: "panel",
scrollable:true,
items: [
{
xtype:"toolbar",
title:"Test app"
},
{
xtype:"UserLoginView",
id: "LoginForm"
}
]
}
]
}
});
控制器,一切正在發生
//Define controller name
Ext.define('App.controller.User', {
//Extend the controller class
extend: 'Ext.app.Controller',
views: ['user.Login','user.Index'],
refs: [
{
selector:"#userLogin",
ref: 'LoginUserLogin'
},
{
selector:"#userPassword",
ref: "LoginUserPassword"
},
{
selector: "Viewport",
ref: "Viewport"
},
{
selector: "UserIndex",
ref: "UserIndex"
}
],
//define associated views with this controller
init: function()
{
//do something and setup listeners
//setup listeners
this.control({
'#UserLoginButon' : {
tap : this.login
}
});
},
//handle
login : function (object)
{
//iniate loading screen for user
var loadingScreen = new Ext.LoadMask(Ext.getBody(),{msg: ""});
loadingScreen.show();
//get form values
var username = this.getLoginUserLogin().getValue();
var password = this.getLoginUserPassword().getValue();
//check for empty fields
if(username == "" || password == "")
{
loadingScreen.hide();
Ext.Msg.alert("Foutmelding","Je dient alle velden in te vullen.");
}
else
{
Ext.Ajax.request(
{
url: '../backend/users/login/'+username+'/'+password,
method: 'post',
failure : function(response)
{
loadingScreen.hide();
data = Ext.decode(response.responseText);
Ext.Msg.alert('Login Error', data.errorMessage, Ext.emptyFn);
},
success: function(response, opts)
{
data = Ext.decode(response.responseText);
if (data == true)
{
loadingScreen.hide();
Ext.Msg.alert("ingelogd!","welkom");
//THIS IS WHERE IT GOES WRONG
App.view.Viewport.setActiveItem("App.view.user.Index",{
type: "slide",
direction: "left"
});
} else
{
loadingScreen.hide();
Ext.Msg.alert("Foutmelding","Gebruikersnaam of wachtwoord klopt niet.");
}
}
});
}
console.log(App);
},
loginRequest : function (username, password)
{
}
});
偉大似乎做的工作!儘管我可以保留我在App.view.Viewport中所具有的工具欄,但這可能會消失。 – user1035654
你可以有一個包含兩個項目的包裝容器,一個是工具欄(停靠:'頂部'),另一個是另一個容器,你保持你的「活動」面板。因此,你可以通過引用第二個項目你的控制器或組件查詢並摧毀裏面的內容,添加你的新面板並將其設置爲活動。我沒有任何有關我的確切功能的代碼示例,但您可以嘗試使用它。 – stan229
是不是有可能將indexPanel輕鬆添加到已經存在並創建的視口?我猜這是一個非常普遍的過程 – user1035654