<div ng-controller="SidebarController">
<a id="treeView" ej-treeview e-fields-datasource="dataList" e-fields-id="id" e-fields-parentid="pid" e-fields-text="name" e-datasource="localdata" e-fields-haschild="hasChild" e-fields-expanded="expanded" e-fields-imageurl="imageUrl" e-nodeselect="selected" />
var ListViewData = [
{ id: 1, name: "Fiction Book Lists", hasChild: true, expanded: true },
{ id: 2, pid: 1, name: "Fiction Book1", url: '../view/fictionbooks/FictionBook1.html' },
{ id: 3, pid: 1, name: "Fiction Book2" },
{ id: 4, name: "Mystery Book Lists", hasChild: true, expanded: true },
{ id: 5, pid: 4, name: "Mystery Book1" , url: '../view/mysterybooks/MysteryBook1.html' },
{ id: 6, pid: 4, name: "Mystery Book2" },
{ id: 7, name: "Horror Novels", hasChild: true },
{ id: 8, pid: 7, name: "Horror Book1" },
{ id: 9, name: "Novel Lists", hasChild: true },
{ id: 10, pid: 9, name: "Novel Book1" }];
在上面的json数据{id:2,pid:1,name:“Fiction Book1”,}等我必须传递上面json数据中显示的一个客户url字符串 在上面的json数据中 {id:2,pid:1,名称:“Fiction Book1”,}等我必须传递上面json数据中显示的一个客户url字符串,当我点击它时,应该可以在所选函数中访问“args.url”树视图中的节点
喜欢
$scope.selected = function (args) {
//here i have to access that url string
}
答案 0 :(得分:0)
我们可以按如下方式访问nodeSelect
中的选定节点记录。
$scope.selected = function(args){
var getdata = function (data, id) {
var len = data.length;
while (len--) {
if (data[len]["id"] == id)
return data[len]["url"];
}
}
console.log(getdata(args.model.fields.dataSource, +args.id));
}
请参阅以下链接,了解在nodeSelect
活动中获得的参数。
http://help.syncfusion.com/UG/JS_CR/ejTreeView.html#event:nodeSelect
答案 1 :(得分:0)
首先,我们需要将属性“url”映射到属性“ linkAttribute ”,如下所示。此属性将指定的属性添加到Tree nodes anchor元素
<div>
<a id="treeView" ej-treeview e-fields-datasource="dataList" e-fields-id="id" e-fields-parentid="pid" e-fields-text="name" e-datasource="localdata" e-fields-haschild="hasChild" e-fields-expanded="expanded" e-fields-imageurl="imageUrl" e-nodeselect="selected" e-fields-linkattribute="url" />
</div>
然后在' nodeselect '事件参数中,我们可以获取所选节点。从所选节点,我们可以找到获取Url的锚元素。
$scope.selected = function (args) {
console.log($(args.currentElement).find("a").attr("href"));
}
这对你有用。