我在Ares中使用listselectors填充了两个列表,这样列表ONE包含A,B,C,D,列表TWO包含E,F,G,H。如何预先过滤第二个列表,这样当项目A是从列表ONE中选择,它预先过滤列表TWO以显示F,G?
我到目前为止的代码是:
function FinalAssistant(argFromPusher) {
}
FinalAssistant.prototype = {
setup: function() {
Ares.setupSceneAssistant(this);
},
cleanup: function() {
Ares.cleanupSceneAssistant(this);
},
listSelector1Change: function(inSender, event) {
this.$.getListSelector2.choices["F"]
},
};
编辑添加:
我添加了回调函数和清理方法,但它仍未传递参数F& -G。
代码如下
FinalAssistant.prototype = {
setup: function() {
Ares.setupSceneAssistant(this);
this.controller.listen("listSelector1", Mojo.Event.listSelector1Tap, this.listSelector1Tap.bindAsEventListener(this));
},
cleanup: function() {
Ares.cleanupSceneAssistant(this);
Mojo.Event.stopListening(this.controller.listSelector1,Mojo.Event.listSelector1Tap,this.listSelector1Tap)
},
listSelector1Tap: function(inSender, event) {
switch (event.choices.label)
{
case 'A':
this.listModel2.choices = [{label: "F"}, {label: "G"}];
this.controller.modelChanged(this.listModel2);
break;
case 'B':
this.listModel2.choices = [{label: "H"}, {label: "I"}];
this.controller.modelChanged(this.listModel2);
break;
}
},
};
Mojo日志信息错误表示必须定义Mojo.Event.listen'target'参数
答案 0 :(得分:1)
你想做的事情相当简单。首先,因为它似乎不是,你需要在你的设置功能中设置Mojo.Event.listTap
的回调:
this.controller.listen('list1', Mojo.Event.listTap, this.list1Tap.bindAsEventListener(this))
然后你需要在你的清理中做stopListening
以避免留下僵尸听众。
另外,由于我在这里看不到它,你需要在某个地方存储列表模型,即。包含列表项的对象。在这里,我假设它list2Model
为list2
。
至于list1Tap
,您需要以下内容:
list1Tap: function(event) {
switch (event.item.label)
{
case: 'A':
this.list2Model.items = [{label: "F"}, {label: "G"}];
this.controller.modelChanged(this.list2Model);
break;
}
},
那应该这样做。显然,你需要更多的结构才能让它100%工作,但这就是你要问的部分。