Javascript 尝试多次更新淘汰版Js Viewmodel
我是击倒JS领域的新手。我试图在绑定了一个新的JSON对象后更新我的视图模型。然而,我的尝试是徒劳的。有人能看出我做错了什么吗?(以下是我的提琴样本) JS Html/模板:Javascript 尝试多次更新淘汰版Js Viewmodel,javascript,mvvm,knockout.js,Javascript,Mvvm,Knockout.js,我是击倒JS领域的新手。我试图在绑定了一个新的JSON对象后更新我的视图模型。然而,我的尝试是徒劳的。有人能看出我做错了什么吗?(以下是我的提琴样本) JS Html/模板: <div class="widget hide" id="MedNecContainer"> <div class="widget-header"> <h3>Med Nec Results</h3> </div> <d
<div class="widget hide" id="MedNecContainer">
<div class="widget-header">
<h3>Med Nec Results</h3>
</div>
<div class="widget-content">
<div class="controls controls-row">
<table class="table table-bordered table-hover" >
<thead>
<tr>
<th>#</th>
<th>CPT© Code</th>
<th>Error E</th>
<!--th>Description</th-->
<th>Question(s)</th>
<th>Status</th>
</tr>
</thead>
<tbody id="tbCPTResults" data-bind="template: { name: 'med-nec-results-row', foreach:list.CPTResults(), 'if': list.CPTResults() && list.CPTResults().length > 0}">
</tbody>
</table>
</div>
</div>
</div>
<script type="text/html" id="tweetsTemplate">
</script>
<script type="text/html" id="med-nec-results-row">
<tr>
<td data-bind="text: $index"></td>
<!--td data-bind="text: cptAndDescription"></td-->
<td data-bind="text: CPT.Description"></td>
<td data-bind="text: ErrorE"></td>
<td>
<table class="table table-bordered">
<tbody data-bind="template: { name: 'med-nec-results-question-row',
foreach: Questions(),
'if': Questions() && Questions().length > 0
}">
</tbody>
</table>
</td>
<td></td>
</tr>
</script>
<script type="text/html" id="med-nec-results-question-row">
<tr class="med-nec-questions">
<td data-bind="text:Question"></td>
<!--td data-bind="text:QuestionExplanation"></td-->
<td>
<select class="cpt-question" data-bind="options: QuestionPossibleAnswers,
optionsText: 'OptionText',
value: QuestionUserAnswer,
optionsCaption: 'Choose...'">
</select>
</td>
</tr>
</script>
Med Nec结果
#
CPT©代码
误差E
问题:
地位
有几件事:
viewModel.list
可见,以便您的视图可以对list
被分配到新值作出反应:
viewModel = {
list: ko.observable(objViewModel)
};
newList
:
var newList = ko.mapping.fromJSON(strModifiedJSON, CPTResultsMappingOptionsFunctions);
viewModel.list(newList);
主体上的模板
绑定
:
<tbody id="tbCPTResults" data-bind="template: { name: 'med-nec-results-row', foreach:list().CPTResults(), 'if': list().CPTResults() && list().CPTResults().length > 0 }">
更新示例:非常感谢您的帮助。我还想知道如果我移动了这个代码var newList=ko.mapping.fromJSON(strModifiedJSON,CPTResultsMappingOptionsFunctions);viewModel.list(newList);对于self.setDropdownOnChange函数,它不起作用。你知道为什么吗?@user2014809:如果我在分配事件处理程序的函数中放了一条日志语句,它看起来好像从未被调用过。啊,我必须为select onchange创建一个自定义绑定才能让它工作。非常感谢你帮助我!
<tbody id="tbCPTResults" data-bind="template: { name: 'med-nec-results-row', foreach:list().CPTResults(), 'if': list().CPTResults() && list().CPTResults().length > 0 }">