js這是我的第一個程序之一。我有兩個代碼分開的文件,我不知道如何將這兩段代碼合併成一個代碼。我知道這看起來很容易,但我bieng一個新手,您的幫助將受到高度讚賞。如何在knockout.js中結合這兩個代碼?
//Knockout file to add/ remove rows
<html>
<script src="C:\Users\neha.uniyal\Downloads\knockout-3.3.0.js" type="text/javascript"></script>
<script>
function InsertRow(name) {
var self = this;
self.name = name;
}
function AppViewModel() {
var self = this;
// Editable data
self.rows = ko.observableArray([
new InsertRow(""),
]);
self.addRow= function() {
self.rows.push(new InsertRow(""));
}
self.removeRow= function(row) { self.rows.remove(row) }
}
ko.applyBindings(new AppViewModel());
</script>
<body>
<h2>Application</h2>
<table>
<thead><tr>
<th>File name</th>
</tr></thead>
<tbody data-bind="foreach:rows">
<tr>
<td><input data-bind="value: name" /></td>
<td>
<select>
<option value="yes">Yes</option>
<option value="no" selected>No</option>
</select></td>
<td><a href="#" data-bind="click: $root.removeRow">Remove</a></td>
</tr>
</tbody>
</table>
<button data-bind="click:addRow">Add Row</button>
</body>
</html>
//File to display upload-file control on selecting yes option:
<html>
<script src="C:\Users\neha.uniyal\Downloads\knockout-3.3.0.js" type="text/javascript"></script>
<script>
var viewModel = {
types: ["Yes", "No"],
type: ko.observable("No"),
isType: function(type) {
return type === this.type();
}
};
ko.applyBindings(viewModel);
</script>
<body>
Choose : <select data-bind="options: types, value: type"></select>
<hr/>
<span data-bind="visible: isType('Yes')"><input type = "file"> </span>
<span data-bind="visible: isType('No')" ></span>
</body>
</html>
你的意思是說,你要合併2個虛擬機到一個虛擬機? –
我可以在第二個html文件中看到選擇下拉菜單。你想把它放在第一個HTML文件中而不是選擇嗎?你能否提供更多細節? –