0
私は数多くの項目を持つツリー構造を持っていますので、非常に遅いです。私はもう少しパフォーマンスを得るためにJavaScriptで書き直そうとしています。しかし、私はng-click
で立ち往生しています:foreachループ内でng-clickでhtml文字列をコンパイルします
HTML:
<jstree initialstructure="vm.initialStructure" get-child-nodes="vm.getChildNodes()"></jstree>
JS:
(function() {
angular
.module('app.jstree')
.directive('jstree', Jstree);
Jstree.$inject = ['$compile'];
function Jstree($compile) {
var directive = {
restrict: 'E',
controller: 'JstreeController',
controllerAs: 'jst',
replace: true,
scope: {
initialstructure: '=',
getChildNodes: '&'
},
link: function (scope, element, attrs) {
scope.$watch('initialstructure', function (items) {
if (items) {
var html = "";
angular.forEach(items, function (item) {
html = html.concat('<li ui-tree-node>' + item.title);
var selectedNodeCls = item.selected ? 'selected-node' : '';
html = html.concat('<div ui-tree-handle ng-click="alert(item);" class="' + selectedNodeCls + '" tooltip="' + item.title + '">');
html = html.concat('</div>');
html = html.concat('</li>');
});
element.html(html);
element = $compile(element)(scope);
}
scope.alert = function(item) {
console.log(item); //this is undefined, obviously because it is not on the scope
}
});
}
};
return directive;
}
})();
をどのようにこれが解決されるだろうか?私は何かを行っている
あなたには、いくつかのより多くのコードを置くことができます。私はエラーを再現しようとしています、そして、私はあなたのコードがどのように見えるかについて多くの仮定をしなければなりません。 –
@DarinCardinはやったけど、初めて書いたものにほかならない。そのコードを内側に置いてください。関連する問題はng-clickです。どのような方法でその作業を行うのですか? – bokkie
置き換えられたhtmlを角度に再バインドしようとすることができます。を見て:http://stackoverflow.com/questions/27131078/how-to-replace-a-html-content-with-jsf-rerender-or-ajax-load-and-rebind-the-new –