- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想知道在 qooxdoo qx.ui.form.VirtualComboBox 中是否有使用键、值对的首选方法。我希望在文本框中设置名称,但在请求时应返回 id。我见过的这个小部件的所有示例都仅使用该值。我发布了如何解决问题的代码,但我想知道是否有更好/首选的使用数据绑定(bind)的方法。到目前为止,每次我需要值或键时,我都会循环遍历模型以找到匹配项。这是 Playground 示例:http://tinyurl.com/neyfwva
//John is set for testing purposes
var myJSONObject = {"personal": [
{"name": "Martin", "id": "1", "age": "32"},
{"name": "Horst", "id": "2", "age": "55"},
{"name": "Peter", "id": "3", "age": "23"},
{"name": "John", "id": "2", "age": "40"} ]
};
var jsonmodel = qx.data.marshal.Json.createModel(myJSONObject);
var comboBox = new qx.ui.form.VirtualComboBox(jsonmodel.getPersonal());
comboBox.setLabelPath("name");
comboBox.setDelegate({bindItem : function(controller, item, id) {
controller.bindProperty("name", "label", null, item, id);
controller.bindProperty("id", "model", null, item, id);
}});
this.getRoot().add(comboBox);
//#################################################################
//-->> get "ID" from selected value
var button1 = new qx.ui.form.Button("get ID from selectbox");
this.getRoot().add(button1,
{
left : 20,
top : 50
});
button1.addListener("execute", function(e) {
var model = comboBox.getModel();
var selection= null;
for(var i = 0, l = model.getLength(); i < l; i++){
if(model.getItem(i).getName() === comboBox.getValue()){
selection = model.getItem(i);
break;
}
}
if(selection){
alert(selection.getId());
}
});
//#################################################################
//#################################################################
//-->> set value "Horst" by giving id
var button2 = new qx.ui.form.Button("set ID -2- (also Horst)");
this.getRoot().add(button2,
{
left : 200,
top : 50
});
button2.addListener("execute", function(e) {
var model = comboBox.getModel();
var selection = null;
for(var i =0, l = model.getLength(); i < l; i++){
if(model.getItem(i).getId() === "2"){
selection = model.getItem(i);
break;
}
}
if(selection){
comboBox.setValue(selection.getName());
}
});
最佳答案
qx.ui.form.VirtualComboBox
的子控件dropdown
具有正常的选择数据数组。尽管 Qooxdoo 的 API 引用和文档非常好且详尽,但对于这种情况的建议是源代码就是您的文档(您可以按照从 API 引用直接转到方法的源代码查看源代码链接)。 Qooxdoo 的代码同样优秀且易于理解。
这是modified snippet :
var data = {"personal": [
{"name": "Martin", "id": "1", "age": "32"},
{"name": "Horst", "id": "2", "age": "55"},
{"name": "Peter", "id": "3", "age": "23"},
{"name": "John", "id": "2", "age": "40"}
]};
var model = qx.data.marshal.Json.createModel(data);
var comboBox = new qx.ui.form.VirtualComboBox(model.getPersonal());
comboBox.setLabelPath("name");
this.getRoot().add(comboBox);
var getButton = new qx.ui.form.Button("Get id");
this.getRoot().add(getButton, {'left': 20, 'top': 50});
getButton.addListener("execute", function()
{
var selection = comboBox.getChildControl('dropdown').getSelection();
if(selection.getLength())
{
this.debug('Here is your id', selection.getItem(0).getId());
}
}, this);
var setButton = new qx.ui.form.Button("Set id:2");
this.getRoot().add(setButton, {'left': 200, 'top': 50});
setButton.addListener("execute", function()
{
// don't replace selection object as it's used internally
var selection = comboBox.getChildControl('dropdown').getSelection();
selection.push(model.getPersonal().getItem(1));
}, this);
如果您需要通过id
或另一个项目的属性选择一个项目,qx.data.Array
不会直接帮助您,因为它是一个数组,而不是字典。您必须选择:
预先计算 id -> index
映射并稍后使用:
var mapping = data['personal'].reduce(function(result, item, index)
{
result[item['id']] = index;
return result;
}, {});
var selection = model.getPersonal().getItem(mapping['2']);
或者按需过滤数据数组:
var selection = model.getPersonal().filter(function(item)
{
return item.getId() == '2';
});
如果您的列表很大并且选择频繁,那么前者是更好的选择。
关于javascript - qooxdoo qx.ui.form.VirtualComboBox 键值对,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31010468/
我想拿一个简单的网页,让非技术管理员只需登录,浏览要更改的页面,点击文本进行更改,或拖动简单列表重新排序,即可修改内容他们。 我的问题是 qooxdoo 是否是这个用例的一个不错的选择。我希望文本像往
我正在为 qx.mobile 开发一个 ClojureScript 包装器,并希望以编程方式构建一个 cljs 类型层次结构来镜像 qx 类层次结构。 有没有办法获取一个qooxdoo类的所有子类?
我正在玩并测试qooxdo-compiler,如何进行部分编译? 我有这个脚本,但它在 Window 或 Linux 中不起作用。 Application.js /* * * @use(webApp.
我想列出 qooxdoo 对象的所有成员。我找到了一种方法来做到这一点,但我认为一定有更清洁的方法吗? for (var key in obj) { if (key.startsWith('$$u
我正在尝试摇动窗口,但控制台中出现错误。我的代码: var win = new qx.ui.window.Window ("Login"); win.setLayout (new qx.ui.
我在使用基本的 qooxdoo 对象时遇到错误。我可以很好地使用某些东西,但是当我这样做时出现错误: var controller = new qx.data.controller.Object();
我有固定列顺序的数据。但是,有时我想在不修改数据的情况下更改表中显示的列的顺序。谢谢你的帮助。 最佳答案 实际上有两种方法可以做到这一点。两者都是“表列模型”的方法。第一种方法是 setColumns
PubNub 通过调用您指定的回调函数来工作,如下所示: http://www.pubnub.com/account-javascript-api-include 如何将其与 Qooxdoo JS 框
我也很困惑这两个框架中的哪一个要学习。大多数比较是在 sproutcore 和 Cappuccino 或 qooxdoo 与 jquery 之间。如果条件是一个 JS 框架: 1. 构建像 web 应
我下载了 Qooxdoo,然后是 ActivePython 并按照本教程中的方式安装它 http://qooxdoo.org/documentation/1.1/helloworld 。当我按照说明操
qooxdoo提供了优秀的单元测试框架,但没有代码覆盖工具。 Coveralls很棒,但仅限于公共(public)项目;私有(private)/商业或尚未发布的项目怎么样? 周围有很多 JavaScr
这是我的代码: var sb = new qx.ui.form.SelectBox(); sb.add( new qx.ui.form.ListItem("English") ); sb.add( n
当我在 qooxdoo 中最小化窗口时,它会去哪里?有没有办法让它粘在主应用程序窗口的底部? 谢谢! 最佳答案 没有对此的内置支持,您需要自己动手。基本上,子类 window.Window 覆盖图标化
我制作了自定义列表项 View (基于 http://news.qooxdoo.org/tutorial-part-4-2-custom-widgets-4 )。 我对此列表中的选择项目有疑问。总是选
我有一个完整的 qooxdoo 桌面应用程序和一个新创建的移动应用程序。我想在我的移动应用程序中重用桌面应用程序中的现有类。我修改了配置文件,以便编译器知道路径。 仅仅将桌面小部件添加到移动页面是不可
在我的应用程序中,我正在从qx.io.rest.Resource加载/保存一些数据。 。为了隐藏 REST 的复杂性,我想向应用程序组件公开一个简化的高级接口(interface);考虑 load()
我使用的是 qooxdoo 5.0.1,但表格标题工具提示存在性能问题。 目前表格只有 49 列,我得到了 44 列的工具提示。 仅创建表格和格式化其中的列大约需要 40 秒。 如果没有表格标题工具提
我正在尝试以不同的颜色显示表格的行。请帮助我实现这一目标。请提供示例代码来执行相同操作。谢谢。 问候,维扬卡特什 最佳答案 维扬卡塔什 您可能在 qooxdoo mailing list 上看到了答案
我现在已经使用 qooxdoo 3 天了,这只是开始,但显然我已经遇到了一些麻烦。 它是关于 VBox HBox 的……我不太明白它是如何工作的。我看到了在线文档和论坛,但无论我尝试什么,我都无法用我
我有简单的应用程序,我需要从 MySQL 获取数据。我读到我可以使用 *.php 文件中服务器上的脚本来完成此操作,我所需要做的就是从我的 qooxdoo 应用程序运行此文件并获取打印数据。这是一段代
我是一名优秀的程序员,十分优秀!