我有一个与AngularJS集成的webix表单,使用此框架遇到的挑战越来越多。到目前为止,我坚持使用它,因为我认为它是最合适的选择。如果需要,我很乐意发布代码。
但是我只是想问问我的richselect(基于AngularJS)如何或为什么在初始表单提交时一直保持原始值(不重新加载页面)。另外,在页面重新加载(提交时)时,我的richselect会采用适当的值。
如何解决此问题?
<div id="formcontainer" ng-app="Risk" ng-controller="EditRiskController as ctrl">
<get-risk></get-risk>
<div ng-if="ctrl.initDone && ctrl.userDone" id="myeditform" layout-padding="" ng-cloak="">
<form id="form" name="EditRisk" role="form"
ng-submit="ctrl.valid() && ctrl.submit()" novalidate>
<div ng-show="ctrl.config.owner.done" config="owner"
webix-ui="owner" id="owner" width="200" height="30"
name="owner" options="users" type="richselect" />
<button id="submit" type="submit" class="raised primary">
Edit Risk
</button>
</form>
</div>
</div>
RichSelect初始化代码
if (view == "richselect")
{
config.value = scope.ctrl.risk[attr] || 0;
config.options = scope.ctrl[options];
config.on = {
"onChange": function(){
var obj = this.eventSource || this;
scope.ctrl.getItemValueAndValidate(obj, scope.ctrl, attr);
}
};
}
获取配置初始化代码中引用的项目值(不进行验证)
commonFunctions.getItemValue = function(obj, scope, type, field){
if (!obj && !obj.getValue()){
scope[type][field] = '';
return;
}
scope[type][field] = obj.value || obj.data.value;
}
答案 0 :(得分:0)
请参见下面的代码,其中添加config.value = obj.getValue();
可以完全解决问题。
if (view == "richselect")
{
config.value = scope.ctrl.risk[attr];
config.options = scope.ctrl[options];
config.on = {
"onChange": function(){
var obj = this.eventSource || this;
scope.ctrl.getItemValueAndValidate(obj, scope.ctrl, attr);
config.value = obj.getValue(); //adding this fixed the problem
}
}
}