【发布时间】:2016-11-28 07:09:10
【问题描述】:
我在 Umbraco 7.4.3 中有一个自定义数据类型,它有一个类型为 number 的简单输入。这使用 ng-bind 属性绑定到模型,但文本框不呈现该值。
NumberTestInput.Editor.html
<div ng-controller="NumberTestInput.NumberTestInputController">
<!--Changing the type to 'text' causes the value to render correctly-->
<!--Otherwise, it renders with an empty value-->
<input type="number" ng-model="model.value" />
</div>
NumberTestInput.Controller.js
angular.module("umbraco").controller("NumberTestInput.NumberTestInputController", function ($scope) {
//Causes value to load on page load, but textbox is blanked out again after publishing
//$scope.model.value = parseInt($scope.model.value);
});
package.manifest
{
"propertyEditors": [
{
"name": "Number Test Input",
"alias": "numberTestInput",
"editor": {
"hideLabel": false,
"isReadOnly": false,
"valueType": "INT",
"view": "~/App_Plugins/NumberTestInput/NumberTestInput.Editor.html"
}
}
],
"javascript": [
"~/App_Plugins/NumberTestInput/NumberTestInput.Controller.js"
]
}
看起来模型值类型设置为字符串而不是数字的问题,尽管我在清单中将此设置为 INT,并且在输入时正确保存了值。只是它们没有在 UI 中正确呈现。我需要做些不同的事情才能让它发挥作用吗?
【问题讨论】:
-
model.value的实际值是多少? -
@developer033 这是一个数值。值本身被正确存储,通过将文本框类型从“数字”更改为“文本”来证明。
标签: angularjs binding model umbraco