0

我正在使用 dojox.mobile.ScreenSizeAware 进行平板电脑/手机定位。

当 ScreenSizeAware 处于平板电脑模式时,我想禁用我的应用程序中的一些按钮。

我检查了文档,有一种方法 isPhone() 用于识别当前显示模式。但是,我不知道如何调用此方法。

这是我的相关 HTML 标记的方式:

<span data-dojo-type="dojox/mobile/ScreenSizeAware" id="sszaware"></span>
<div data-dojo-type="dojox/mobile/FixedSplitter" data-dojo-props='orientation:"H"' id="mainSplitter">

我尝试了以下 javascript 代码,但它说 object / HTMLDivElement has no method isPhone:

alert(digit.byId('sszaware').isPhone()); //error
alert(digit.byId('mainSplitter').isPhone()); //error
alert(dojo.byId('sszaware').isPhone()); //error
alert(dojo.byId('mainSplitter').isPhone()); //error

我还尝试了以下方法,甚至给出了错误:

require(["dojox/mobile/ScreenSizeAware"], function(sSzAw){
    alert(sSzAw.isPhone()); //error
});

我已经订阅了以下主题以在模式更改时触发我的代码。然而,这些主题/事件仅在显示模式从手机更改为平板电脑时触发,反之亦然。当网页刚刚在浏览器中加载时,它们不会在开始时触发。

require(["dojo"], function(dojo){
    dojo.subscribe("/dojox/mobile/screenSize/tablet", function(dim){ //this works fine when orientation changes from phone to tablet mode
    alert("Reorienting tablet");
    showButtons(false);
});

dojo.subscribe("/dojox/mobile/screenSize/phone", function(dim){ //this works fine when orientation changes from tablet to phone mode
    alert("Reorienting phone");
    showButtons(true);
});
});

我做了很多搜索,但找不到有关 ScreenSizeAware 编程用法的示例。最终,我要找 stackoverflow 的专家来解决我的问题。

提前感谢您的回复。

4

2 回答 2

0

尝试这个:

require(["dojo/ready", "dojox/mobile/ScreenSizeAware"], function(ready, ssa) {
    ready(function(){
        console.log("isPhone: " + ssa.getInstance().isPhone());
    });
});

(例如,请参阅 dojox/mobile/tests/test_ScreenSizeAware-demo-tag.html)。

于 2013-10-21T08:36:31.800 回答
0

Try using dijit.byId in stead of dijit/byId. And if you're using AMD syntax, it should be

require(["dijit/registry"], function(registry) {
    console.log(registry.byId("sszaware").isPhone());
});

But keep in thoughts that the dojox/mobile/ScreenSizeAware module is reported as being experimental. The API might change drastically when you change versions.

于 2013-10-14T07:38:55.973 回答