我正在为 {N} 使用 Telerik UI Pro 组件(不支持)并且 DataForm 存在一些问题。
当我将对象传递给页面上下文时,使用 Picker 编辑器的所有字段都无法选择正确的值。
我将展示我编写的代码:
teste-model.js
var Value = (function() {
function Value(text, value) {
this.text = text;
this.value = value;
}
return Value;
})();
var ValueModel = (function() {
function ValueModel() {}
Object.defineProperty(ValueModel.prototype, "model", {
get: function () {
if (!this._model) {
this._model = new Value("This is a text", "VALUE 1");
}
return this._model;
},
enumerable: true,
configurable: true
});
return ValueModel;
})();
exports.Value = Value;
exports.ValueModel = ValueModel;
teste.js
var ValueModel = require("./teste-model").ValueModel;
var page;
exports.onPageLoaded = function(args) {
console.log("Carregando página...");
page = args.object;
page.bindingContext = new ValueModel();
console.log(JSON.stringify(page.bindingContext));
}
teste.xml
<Page loaded="onPageLoaded"
xmlns:df="nativescript-telerik-ui-pro/dataform">
<StackLayout>
<df:RadDataForm id="myDataForm" source="{{ model }}">
<df:RadDataForm.properties>
<df:EntityProperty name="text" displayName="Text" index="0" />
<df:EntityProperty name="value" displayName="Value" index="1" valuesProvider="VALUE 0, VALUE 1, VALUE 2">
<df:EntityProperty.editor>
<df:PropertyEditor type="Picker" />
</df:EntityProperty.editor>
</df:EntityProperty>
</df:RadDataForm.properties>
</df:RadDataForm>
</StackLayout>
</Page>
字段值应显示“VALUE 1”但显示“VALUE 0”:
有什么技巧可以解决这个问题吗?
更新
我已经做出了 Vladimir 推荐的更改,但选择器属性仍然没有反映对象更改。
我还在页面上添加了一个按钮,用随机值填充数据表单。text 属性通常会监听更改,但 picker 属性不会。
如果我选择一个选择器值并单击该按钮,则该属性将重置为第一个提供程序值。
实际代码是:
teste.xml
<Page loaded="onPageLoaded"
xmlns:df="nativescript-telerik-ui-pro/dataform">
<StackLayout>
<df:RadDataForm id="myDataForm" source="{{ model }}">
<df:RadDataForm.properties>
<df:EntityProperty name="text" displayName="Text" index="0" />
<df:EntityProperty name="value" displayName="Value" index="1" valuesProvider="VALUE 0, VALUE 1, VALUE 2">
<df:EntityProperty.editor>
<df:PropertyEditor type="Picker" />
</df:EntityProperty.editor>
</df:EntityProperty>
</df:RadDataForm.properties>
</df:RadDataForm>
<Button text="change" tap="changeModel" />
</StackLayout>
</Page>
teste.js
exports.onPageLoaded = function(args) {
console.log("Carregando página...");
page = args.object;
page.bindingContext = new ValueModel();
}
exports.changeModel = function(args) {
var arr = ["VALUE 0", "VALUE 1", "VALUE 2"];
page.bindingContext.set("model", new Value(
Math.random(10000, 99999).toString()
, arr[Math.floor(Math.random() * arr.length)]
)
);
console.log(JSON.stringify(page.bindingContext.model));
}
teste-model.js
var Observable = require("data/observable").Observable;
var Value = (function() {
function Value(text, value) {
this.text = text;
this.value = value;
}
return Value;
})();
var ValueModel = (function(_super) {
__extends(ValueModel, _super);
function ValueModel() {
_super.call(this);
this.model = new Value("This is a texte","VALUE 1");
}
Object.defineProperty(ValueModel.prototype, "model", {
get: function () {
return this.get("_model");
},
set: function(_model) {
this.set("_model", _model);
},
enumerable: true,
configurable: true
});
return ValueModel;
})(Observable);
exports.Value = Value;
exports.ValueModel = ValueModel;