【发布时间】:2015-03-23 11:27:22
【问题描述】:
如何绑定未定义的文本?例如名称不可用:
<table id="recordTbl" data-bind="visible: records().length > 0" class="table">
<thead>
<tr>
<th class="col-md-4">ID</th>
<th class="col-md-4">Name</th>
</tr>
</thead>
<tbody data-bind="foreach: records">
<tr>
<td data-bind="text: id"></td>
<td data-bind="text: name"></td>
</tr>
</tbody>
</table>
我收到此错误:
Uncaught ReferenceError: Unable to process binding "text: function (){return name }"
Message: name is not defined
【问题讨论】:
-
你的意思是
records数组中的某些项目没有name属性吗? -
有办法做到这一点吗?即使对象没有属性(如评论中的名称),我们可以做些什么来阻止异常吗? :O
标签: knockout.js