【发布时间】:2017-04-17 22:22:59
【问题描述】:
我无法在此特定页面上使用 $root 访问方法。此代码适用于我的其他页面,但我不明白。我每页有一个视图模型。它找不到 removeAttachment。
knockout-3.4.0.js:72 Uncaught TypeError: Unable to process binding "click: function (){return $data.bind.removeAttachment($data,event,$index) }" 消息:无法读取未定义的属性“removeAttachment”
var model = function AppViewModel(){
self.removeAttachment = function(data, event, attachmentClicked){
fileNameToDelete = attachmentClicked;
$("deleteText").append(" " + attachmentClicked + "?");
$('#delete-confirm').modal('show');
};
};
var app = new model();
ko.applyBindings(app, document.getElementById("panel"));
<div id="panel">
<tbody class="types">
<!-- ko foreach: multiFileData().fileArray -->
<tr>
<td><span class="attachName" data-bind="text:name"></span></td>
<td><span class="attachName" data-bind="$parent.sizeInMB: size"></span></td>
<td id="remove" class="glyphicon glyphicon-trash" data-toggle="modal" data-target="delete-confirm"
data-bind="click:$root.bind.removeAttachment($data, event, $index)"> </td>
</tr>
<!-- /ko -->
</tbody>
</div>
【问题讨论】:
标签: knockout.js