英文原链接:
http://dojotoolkit.org/documentation/tutorials/1.9/mobile/flickrview/part4/
上一篇,
FlickerView: Implementing FeedView,我们实现了Feed view,并且使用JSON请求回来的数据更新ScrollableView。这一篇我们关注Settings view如何处理各种输入小部件(TextBox,Switch,RadioButton)的get和set以及使用跳转事件。
SettingsView属性
我们只需要保留一些小部件引用,以及当前语言选择。
return declare([ScrollableView], {
feedView: '',
tagInput: '',
selectSwitch: '',
selectedLanguage: '',
//...
SettingsView启动
跟我们在FeedView启动方法做的一样:调用父方法和初始化属性:
startup: function () {
this.inherited(arguments);
this.feedView = registry.byId("feed");
this.tagInput = registry.byId("tags");
this.selectSwitch = registry.byId("select");
// ...
}
同时增加一些有用的getters和setters方法:
setTags: function (tags) {
this.tagInput.set('value', tags);
},
getTags: function () {
return this.tagInput.get('value');
},
setTagMode: function (tagmode) {
this.selectSwitch.set('value', (tagmode === "all") ? "on" : "off");
},
getTagMode: function () {
return (this.selectSwitch.get('value') === "on") ? "all" : "any";
}
dojox/mobile/switch有两个状态:on和off.我们准备将ALL设置对应on状态,ANY对应off状态。
继续启动方法,我们创建一个方法,当用户点击单选项时,保留选中的语言。dojo/on的这个强大特性可以实现这个功能:
even delegation with selector.
// handler to record the selected feed language
this.on("[name=feedLanguage]:click", lang.hitch(this, function (e) {
this.selectedLanguage = e.target.value;
}));
接下来做什么?
添加Done按钮的处理方法:
- 编程实现转换回Feed View
- 如果用户修改至少一个设置时,强制刷新视图
// handler to update search query parameters when done button is selected
registry.byId("doneButton").on("click", lang.hitch(this, function () {
// we are done with the settings: transition to FeedView
this.performTransition("feed");
// check if anything changed in the setting view
if (this.getTags() !== flickrview.QUERY.tags ||
this.getTagMode() !== flickrview.QUERY.tagmode ||
this.selectedLanguage !== flickrview.QUERY.lang) {
// update QUERY
flickrview.QUERY.tags = this.getTags();
flickrview.QUERY.tagmode = this.getTagMode();
flickrview.QUERY.lang = this.selectedLanguage;
// force FeedView list refresh
this.feedView.refresh()
}
}));
因为编程实现的转换,所以要关掉小部件自身的自动转换功能,使用 moveTo:'#'
<!-- Settings view -->
<div id="settings"
data-dojo-type="flickrview/SettingsView">
<div data-dojo-type="dojox/mobile/Heading"
data-dojo-props="fixed: 'top', label: 'Settings'">
<span data-dojo-type="dojox/mobile/ToolBarButton"
id="doneButton"
data-dojo-props="label:'Done', moveTo:'#', transition:'none'" style="float:right;"></span>
最后一步就完成了!
响应转换事件
Dojo Mobile提供一组
转换相关的事件,还在在启动方法中,我们设置事件beforeTransitionIn的处理方法,在转换到设置视图时得到通知。
// handler to get notified before a transition to the current view starts
this.on("beforeTransitionIn", lang.hitch(this, function () {
this.setTags(flickrview.QUERY.tags);
this.setTagMode(flickrview.QUERY.tagmode);
this.selectedLanguage = flickrview.QUERY.lang;
registry.byId(this.selectedLanguage).set('checked', true);
}));
在这个处理方法中,我们更新设置视图上的输入小部件,从QUERY对象取到真实的值。
清理代码
这个教程的前面部分,我们首先创建了一个模型应用,这是一个最佳实践,从模型开始可以快速和简便地得到用户体验。
移除HTML中的模型代码
现在我们的应用已经完成,所以可以移除所有的静态模型代码了。这样可以减少代码量和得到整洁的代码。
- FeedView:移除列表项。
- DetailView:移除静态描述。
移除阻止缓存的元标签
移除开发时使用的阻止缓存标签,让应用允许缓存到设备。
<!-- prevent cache -->
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="pragma" content="no-cache">
你成功了!
祝贺!你已经开发完成一个完整的Dojo Mobile应用程序,下一篇(本教程最后一篇)将告诉你怎么将应用产品化。
View Demo
下载源码
下载
Part 4 - FlickrView: Implementing SettingsView.
============================================
Part 4 END
next
Part 5 - Build FlickrView for production
分享到:
相关推荐
Chapter II-4: Real-Time Rendering of Physically Based Clouds Using Precomputed Scattering Chapter II-5: Sparse Procedural Volume Rendering Part III: Lighting Chapter III-1: Real-Time Lighting via ...
Prepare for Microsoft Exam 70-410 – and help demonstrate your real-world mastery of implementing and configuring core services in Windows Server 2012 R2. Designed for experienced IT professionals ...
7. **Exam70-080: Implementing and Supporting Microsoft Internet Explorer 5.0 by Using the Microsoft Internet Explorer Administration Kit** - 本认证涉及使用Internet Explorer Administration Kit安装和...
Uniquely, this book gives in-depth information on upper protocol layers, implementation and deployment issues, and services, making it suitable for engineers who are implementing the technology into ...
ISO 28004-4:2014 Security management systems for the supply chain — Guidelines for the implementation of ISO 28000 — Part 4:Additional specific guidance on implementing ISO 28000 if compliance ...
ISO 11898-4:2004 specifies time-triggered communication in the CAN. It is applicable to setting up a time-triggered interchange of digital information between electronic control units (ECU) of road ...
4. "增/减" - rise, go up, go drop, raise, bring down, reduce, increase, decrease - rise: 上升,如:The temperature rises in summer. - go up: 增加,上升,如:Prices are going up. - go drop: 下降,如...
4. **编程语言**:考生应熟练掌握C#、Python或JavaScript,因为这些语言广泛用于与Azure服务交互,特别是当涉及到编写自定义逻辑或扩展预训练模型时。 5. **REST API和SDKs**:了解如何使用基于REST的API和SDKs是...
### Algorithms in C++, Parts 1-4: Fundamentals, Data Structures, Sorting, Searching #### Part One: Fundamentals ##### Chapter One: Introduction 1. **Algorithms**: This chapter introduces the ...
原理图GraphQL 该网站重点介绍了实现和缩放数据图的最佳做法。 它是通过使用构建的。在本地发展克隆此存储库,安装Node依赖项,然后启动Gatsby开发服务器,以建立用于本地开发的网站。 $ npm install$ npm start部署...
CCNA+CCNP(From 2007-4-7 To 2007-5-4--Friday(5.4)) Teached by MR. MA CCNP+ (From 2007-6-1 TO 2007-7-7) Teached by MR. Chen CCIE Service Provider(SP) (From 2007-7-7 TO 2007-9-7) The following content ...
Module 4: Working with Measures and Measure GroupsThis module describes how to implement measures and measure groups in a cube.Lessons Working with Measures Working with Measure Groups Lab : ...
循环的java源码压缩cs-实施-a-链表实验室 目标 用 Java 实现一个链表。 编写 List 接口的实现。 ...在本实验中,我们提供了 ...接口的部分实现,该接口使用链表来存储元素。...如果数据结构由包含对其他节点的引用的对象...
CCNA Voice Lab Manual addresses all exam topics and offers additional guidance for successfully implementing IP voice solutions in small-to-medium-sized businesses. CCNA Voice 640-461 Official Exam ...
读书笔记:Implementing.DomainDriven.Design实现领域驱动设计 中英文对照翻译
machinepack-svg-精灵从多个 SVG 源文件创建一个 SVG 精灵。安装 $ npm install machinepack-svg-sprite用法该模块的最新使用文档、版本信息和测试状态见 。... 了解更多信息 http://node-machine.org/implementing
- Mode 4: Universal Asynchronous Receiver/Transmitter (URXD3) - Mode 5: Card Multimedia Command Set (CMCSD2) - Mode 6: Card Multimedia Clock (CMCSK) - Mode 7: Enhanced Direct Interface (EDIDO) - ...