这些小部件有单独的问题。dojox /mobile/Switch类与dojo/_base/declare组合的方式不适用于 dojox /mvc如何扩展dijit/_WidgetBase,它是大多数小部件的基类。您需要将扩展显式应用于dojox/mobile/Switch以解决该问题,例如:
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/dojo/1.9.1/dojox/mobile/deviceTheme.js" data-dojo-config="mblThemeFiles: ['base']"></script>
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/dojo/1.9.1/dojo/dojo.js" data-dojo-config="async: 1, parseOnLoad: 0"></script>
<script type="text/javascript">
require([
"dojox/mvc/atBindingExtension",
"dojox/mobile/Switch"
], function(atBindingExtension, Switch){
atBindingExtension(Switch.prototype);
require([
"dojo/Stateful",
"dojox/mvc/at",
"dojox/mobile/parser",
"dojox/mvc/Output"
], function(Stateful, at, parser){
window.at = at;
window.model = new Stateful({
state: "off"
});
parser.parse();
});
});
</script>
</head>
<body>
<div data-dojo-type="dojox/mobile/Switch" data-dojo-props="value: at(model, 'state')"></div>
<div>Switch state: <span data-dojo-type="dojox/mvc/Output" data-dojo-props="value: at(model, 'state')"></span></div>
</body>
</html>
dojox/mobile/DatePicker不会将用户的输入发送回value
属性。您需要value
手动查看每个插槽的更改和更新属性以解决此问题:
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/dojo/1.9.1/dojox/mobile/deviceTheme.js" data-dojo-config="mblThemeFiles: ['base', 'DatePicker']"></script>
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/dojo/1.9.1/dojo/dojo.js" data-dojo-config="async: 1, parseOnLoad: 0"></script>
<script type="text/javascript">
require([
"dojo/_base/array",
"dojo/aspect",
"dojo/date/locale",
"dojo/date/stamp",
"dojo/Stateful",
"dojox/mvc/at",
"dojox/mobile/parser",
"dojox/mobile/DatePicker",
"dojox/mvc/Output"
], function(array, aspect, locale, stamp, Stateful, at, parser, DatePicker){
window.at = at;
window.model = new Stateful({
date: stamp.toISOString(new Date())
});
aspect.after(DatePicker.prototype, "startup", function(){
var self = this,
slots = this.slots;
array.forEach(slots, function(slot){
self.own(slot.watch("value", function(){
var pattern = slots[0].pattern + "/" + slots[1].pattern + "/" + slots[2].pattern;
self._set("value", stamp.toISOString(locale.parse(slots[0].get("value") + "/" + slots[1].get("value") + "/" + slots[2].get("value"), {datePattern: pattern, selector: "date"})));
}));
});
});
parser.parse();
});
</script>
</head>
<body>
<div data-dojo-type="dojox/mobile/DatePicker" data-dojo-props="value: at(model, 'date')"></div>
<div>Date picker value: <span data-dojo-type="dojox/mvc/Output" data-dojo-props="value: at(model, 'date')"></span></div>
</body>
</html>
希望这可以帮助。
最好的, - 阿基拉