Hyperlink EXT JS 5:viewModel链接变量id
我正在使用ExtJS5.0.1,我正在尝试使用视图中定义的viewModel中的链接 下面的例子很有效Hyperlink EXT JS 5:viewModel链接变量id,hyperlink,extjs5,Hyperlink,Extjs5,我正在使用ExtJS5.0.1,我正在尝试使用视图中定义的viewModel中的链接 下面的例子很有效 Ext.define("MyViewPackage.MyView", { extend: "Ext.form.Panel", alias: "widget.myview", theIdToUse: 47, viewModel: { links: { theProject: { type 'mypackage.MyM
Ext.define("MyViewPackage.MyView", {
extend: "Ext.form.Panel",
alias: "widget.myview",
theIdToUse: 47,
viewModel: {
links: {
theProject: {
type 'mypackage.MyModelClassName'
id: 17 //This works. But not theIdToUse or this.theIdToUse.
//I would like to use a value provided from my view
}
}
}
});
我想使用'theIdToUse'的值作为'links'中定义的'theProject'的id属性。
我试着简单地把theIdToUse或this.theIdToUse放进去,但总是出现以下错误:
无法在没有viewModel的情况下使用绑定配置
你知道我如何使用带有变量id的链接吗
提前谢谢 this.theIdToUse不起作用,因为在viewModel的范围内,它不再指MyViewPackage.MyView,而是指viewModel本身 即使您可以获得对MyViewPackage.MyView的引用,例如使用ComponentQuery,组件在viewModel初始化时还不存在,因此您将得到一个错误,无法读取未定义的属性“theIdToUse”
您可能最好在视图和viewModel之间使用某种双向绑定,但我需要更多地了解您试图实现的内容,以说明具体实现方式。前面的答案非常正确,只是在您的情况下,
此
将指窗口,而不是viewModel
。这是由于在Ext.define
中传递的匿名对象没有某些作用域,因此默认情况下将使用window
scope。
假设您应该使用如下内容:
Ext.define("MyViewPackage.MyView", {
extend: "Ext.form.Panel",
alias: "widget.myview",
bind: {theIdToUse: "{id}"}
viewModel: {
links: {
theProject: {
type 'mypackage.MyModelClassName'
id: 17 //This works. But not theIdToUse or this.theIdToUse.
//I would like to use a value provided from my view
}
}
}
});
虽然这个问题是很久以前提出来的,但我给更多的观众留下了一个可能的解决方案 尝试: 您将能够使用不同的ID实例化您的面板:
items: [
{
xtype: 'myview',
theIdToUse: 47
},{
xtype: 'myview',
theIdToUse: 32
}
],
即使:
Ext.create('MyViewPackage.MyView', {theIdToUse: 12}) ;
使用链接到,如:
Ext.define("MyViewPackage.MyView", {
extend: "Ext.form.Panel",
alias: "widget.myview",
theIdToUse: 47,
constructor: function(){
this.callParent(arguments);
this.linkTo('theProject',{
type 'mypackage.MyModelClassName',
id: this.theIdToUse
});
}
});
Ext.define("MyViewPackage.MyView", {
extend: "Ext.form.Panel",
alias: "widget.myview",
theIdToUse: 47,
constructor: function(){
this.callParent(arguments);
this.linkTo('theProject',{
type 'mypackage.MyModelClassName',
id: this.theIdToUse
});
}
});