我的应用程序使用它并且$item
在Knockout 3.4.0
. 我需要访问parentList
,它存储被拖到另一个列表的项目的原始父元素。
下面的代码不会与最新版本的 Knockout 一起运行,而 jQuery 模板是它的依赖项之一。我正在寻找原因、解决方案或解决方法。
带有详细示例的 JSFiddle:http: //jsfiddle.net/piglin/UAcC7/1837/
Uncaught ReferenceError: Unable to process binding "template: function (){return { name:'rowTmpl',foreach:$data.children,templateOptions:{ parentList:$data.children}} }"
Message: Unable to process binding "template: function (){return { name:'cellTmpl',foreach:$data.children,templateOptions:{ parentList:$data.children}} }"
Message: Unable to process binding "sortableItem: function (){return { item:$data,parentList:$item.parentList} }"
Message: $item is not defined
ko.bindingHandlers.sortableList = {};
ko.bindingHandlers.sortableItem = {
init: function(element, valueAccessor) {
var options = valueAccessor();
}
};
var viewModel = function() {
var self = this;
self.children = ko.observableArray(
[{}]
);
};
ko.applyBindings(new viewModel());
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
<script src="https://rniemeyer.github.com/KnockMeOut/Scripts/jquery.tmpl.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/knockout/3.4.0/knockout-min.js"></script>
<div data-bind="template: { name: 'tmpl', foreach: $data.children, templateOptions: { parentList: $data.children } }">
</div>
<script id="tmpl" type="text/html">
<div data-bind="sortableItem: { item: $data, parentList: $item.parentList }">
</div>
</script>