我有一个淘汰可观察数组,其值分配在设定的时间值后发生变化,但在视图中看不到这一点。有人能告诉我哪里做错了吗?我希望输出显示• GRE 1111 • 托福 111但它表明• GRE2 222 • 托福2 22jsFiddle 链接: https: //jsfiddle.net/4r37x9y5/HTML:console.clear();function viewModel() { this.plans = ko.observableArray([]); var plans1 = [ { id: 'GRE', count: '1111' }, { id: 'TOEFL', count: '111' }, ]; var plans2 = [ { id: 'GRE2', count: '222' }, { id: 'TOEFL2', count: '22' }, ]; this.plans = plans2; //this.plans = plans1; setTimeout(function(){ console.log("In timeout before assigning plans"); this.plans = plans1; console.log(this.plans); }, 2000); }ko.applyBindings(viewModel());// The above line equals:// viewModel(); // updates window object and returns null!// ko.applyBindings(); // binds window object to body!<script src="https://cdnjs.cloudflare.com/ajax/libs/knockout/3.4.2/knockout-min.js"></script><div class="panel panel-default"> <ul data-bind="foreach: plans" class="list-group"> <li class="list-group-item"> <span data-bind="text: id"></span> <span data-bind="text: count"></span> </li> </ul></div>
添加回答
举报
0/150
提交
取消