我正在使用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'));
});