AlpacaJS:选择 Select 后以编程方式更改 TextField 的值
AlpacaJS: programmatically change value of TextField after selecting Select
我是 AlpacaJS 的新手,我疯狂地想弄清楚如何做一些简单的事情,比如用 "Select".
的值动态更改文本字段的内容
代码看起来像
$("#form1").alpaca({
"data": {
"name": "Default"
},
"schema": {
"title": "What do you think of Alpaca?",
"type": "object",
"properties": {
"name": {
"type": "string",
"title": "Name"
},
"flavour":{
"type": "select",
"title": "Flavour",
"enum": ["vanilla", "chocolate", "coffee", "strawberry", "mint"]
}
}
},
"options": {
"helper": "Tell us what you think about Alpaca!",
"flavour": {
"type": "select",
"helper": "Select your flavour.",
"optionLabels": ["Vanilla", "Chocolate", "Coffee", "Strawberry", "Mint"]
}
}
},
"postRender": function(control) {
var flavour = control.childrenByPropertyId["flavour"];
var name = control.childrenByPropertyId["name"];
name.subscribe(flavour, function(val) {
alert("Val = " + val);
this.schema.data = val;
this.refresh();
});
}
});
我可以看到调用了 postRenderer 中的函数(因为我可以看到具有相关值的警报)但是(也许我在这个阶段脑死亡)我无法使用该值刷新文本字段。
干杯
我可能是看错了要设置的属性...我改成
后
this.schema.data = val;
它运行良好:)
我是 AlpacaJS 的新手,我疯狂地想弄清楚如何做一些简单的事情,比如用 "Select".
的值动态更改文本字段的内容代码看起来像
$("#form1").alpaca({
"data": {
"name": "Default"
},
"schema": {
"title": "What do you think of Alpaca?",
"type": "object",
"properties": {
"name": {
"type": "string",
"title": "Name"
},
"flavour":{
"type": "select",
"title": "Flavour",
"enum": ["vanilla", "chocolate", "coffee", "strawberry", "mint"]
}
}
},
"options": {
"helper": "Tell us what you think about Alpaca!",
"flavour": {
"type": "select",
"helper": "Select your flavour.",
"optionLabels": ["Vanilla", "Chocolate", "Coffee", "Strawberry", "Mint"]
}
}
},
"postRender": function(control) {
var flavour = control.childrenByPropertyId["flavour"];
var name = control.childrenByPropertyId["name"];
name.subscribe(flavour, function(val) {
alert("Val = " + val);
this.schema.data = val;
this.refresh();
});
}
});
我可以看到调用了 postRenderer 中的函数(因为我可以看到具有相关值的警报)但是(也许我在这个阶段脑死亡)我无法使用该值刷新文本字段。
干杯
我可能是看错了要设置的属性...我改成
后this.schema.data = val;
它运行良好:)