2
我想创建一个自定义占位符控件。下面是代码摘录:绑定资源数据到自定义winjs控件
(function() {
var Placeholder = WinJS.Class.define(function ctor(elem, options) {
this.element = elem || document.createElement('div');
this.element.winControl = this;
WinJS.UI.setOptions(this, options);
this.init();
},
{
element: {
get: function() {
return this._element;
},
set: function (value) {
this._element = value;
}
},
placeholder: {
get: function() {
return this._placeholder;
},
set: function (value) {
this._placeholder = value;
this._placeholderElement.textContent = value;
}
},
placeholderClass: {
get: function() {
return this._placeholderClass;
},
set: function (value) {
this._placeholderClass = value;
this._placeholderElement.classList.add(value);
}
},
_placeholderElement: null,
init: function() {
this._addPlaceholder();
},
_addPlaceholder: function() {
/* Code to add placeholder. */
}
});
WinJS.Namespace.define("ControlX", { Placeholder: Placeholder });
})();
我想以这种方式来使用此控件的HTML:
<div data-win-control="ControlX.Placeholder" data-win-res="{winControl:{placeholder:'resHeight'}}"><input type="text"/></div>
当我使用data-win-res
属性设置占位符值,我得到一个异常:
“无法设置的未定义或空引用属性 '占位符'”
根据这篇文章: How to localize WinJS controls我们也可以将资源字符串绑定到winControl属性。
我在做什么错?
是否有任何其他方式绑定资源字符串到winControl属性?
您是否在页面控制中进行控制?如果是这样,你是否在PageControls的ready函数中调用了WinJS.Resources.processAll(element)?我似乎能够得到这个工作,但我不能说出我们两个努力之间可能会有什么不同。 – 2013-02-19 02:15:31