関数呼び出しを使用して、ある JavaScript から別の JavaScript に値を渡す必要があります。II js から I js に月の値を返していますが、値が html に入力されていません。サンプルコードを以下に示しますが、機能していません。このコードを修正するのを手伝ってください:
HTML FILE
========
<body>
<div id="selectdiv">
<input type="radio" id="radio1" name="radioGrp" value='div1' data-bind="checked:subDiv1" />div1
<input type="radio" id="radio2" name="radioGrp" value='div2' data-bind="checked:subDiv1" />div2</div>
<div id="myDiv" name="myDiv" class="myDiv" style="font-family: Helvetica; font-size: 12pt; border: 1px solid black;">
<div id="subDiv1" name="subDiv1" data-bind="visible:subDiv1()=='div1'" class="subDiv1" style="color: #FF0000; border: 1px dotted black;">
<h5>Section 1</h5>
<p>MONTHS...</p>
<div id="tabContainer">
<ul data-bind="foreach: subDemoMainObj.months()">
<li> <b data-bind="text: $data"></b>
</li>
</ul>
</div>
</div>
<br />
<div id="subDiv2" name="subDiv2" data-bind="visible:subDiv1()=='div2'" class="subDiv2" style="color: #FF00FF;border: 1px dashed black;">
<h5>Section 2</h5>
<p>This paragraph would be your content paragraph...</p>
<p>Here's another content article right here.</p>
</div>
</div>
</body>
I JS FILE(main js file which is calling II js file for getting value of months)
=========
require(["knockout-2.2.1","subDemoMain"],
function(ko,demoMain){
$(document).ready(function() {
alert("ready");
var vm = function () {
var self = this;
self.subDiv1 = ko.observable(false);
self.subDiv2 = ko.observable(false);
self.months = new subDemoMain().getMonths();//ko.observableArray(['Jan', 'Feb', 'Mar', 'etc']);
};
/* var getMonths=function(){
return ko.observableArray(['Jan', 'Feb', 'Mar', 'etc']);
}*/
// alert("ready2");
ko.applyBindings(new vm());
});
});
II JS FILE
=========
define(["knockout-2.2.1"],
function(ko){
alert("ready1");
var getMonths=function(){
return ko.observableArray(['Jan', 'Feb', 'Mar', 'etc']);
}
},
});