我正在使用jQuery Mobile和knockout.js的跨平台移动应用程序。我需要知道重定向到下一页的正确方法。我见过的所有例子都说明了一个包含多个页面的HTML文件。是否可以为每个页面创建单独的HTML文件并为每个HTML页面维护一个单独的JS文件。另外,如何将视图模型链接到每个单独的页面?页面导航 - jQuery Mobile与knockout.js
我的问题如下...
- 我如何从的index.html重定向到Search.html和这些页面之间传递数据?
- 如何为每个页面创建单独的HTML并链接到视图模型?
工作代码示例
的index.html
<div data-role="page" id="Index">
<div data-role="header">
<h1>
jQM</h1>
</div>
<div data-role="content" data-iscroll>
This is jQM Testing
<label for="arrCity">
</label>
<input type="text" class="autocomplete" data-bind="value:aCity" />
<div data-bind="aCity">
</div>
<input id="btn" type="button" data-bind="click:showData" value="showData" />
</div>
<div data-role="footer">
<h1>
jQM Footer</h1>
</div>
</div>
search.html
div id="second" data-role="page">
<div data-role="header">
<h1 data-bind="text: greeting">
</h1>
</div>
</div>
Index.js
$(document).ready(function() {
ko.applyBindings(ReqModel, document.getElementById('Index'));
});
var ReqModel = new ReqModel();
function ReqModel() {
this.aCity = ko.observable('');
this.showData = function() {
alert(this.aCity());
$.mobile.changePage("search.html");
};
}
search.js
var ResviewModel = new ResviewModel(ReqModel);
function ResviewModel(data) {
alert("this load");
}
$(document).ready(function() {
var pre = document.getElementById('Index');
ko.cleanNode(pre);
ko.applyBindings(ResviewModel, document.getElementById('second'));
});