gpt4 book ai didi

javascript - 如何使用 jeasyui 将 $scope.mydata 以 Angular 绑定(bind)到数据选项?

转载 作者:行者123 更新时间:2023-12-02 15:45:21 25 4
gpt4 key购买 nike

我正在使用 jeasyui.com 中的基本 ComboTree

index.js

 $http.get("GetDataForTree")
.success(function (response) {
$scope.Mydata= response;
SpinStop();
});

在cshtml中

 <input class="easyui-combotree" 
data-options="url:'tree_data1.json',method:'get',required:true" style="width:200px;">

how do i bind $scope.Mydata inside data-options ?

最佳答案

这是工作示例。希望这能解决您的问题...

创建一个服务来获取远程数据

app.service('treeData', ['$http',function($http){
this.getData = function(){
return $http.get('tree_data1.json');
}
}]);

tree_data1.json数据

[{
"id":1,
"text":"My Documents",
"children":[{
"id":11,
"text":"Photos",
"state":"closed",
"children":[{
"id":111,
"text":"Friend"
},{
"id":112,
"text":"Wife"
},{
"id":113,
"text":"Company"
}]
},{
"id":12,
"text":"Program Files",
"children":[{
"id":121,
"text":"Intel"
},{
"id":122,
"text":"Java",
"attributes":{
"p1":"Custom Attribute1",
"p2":"Custom Attribute2"
}
},{
"id":123,
"text":"Microsoft Office"
},{
"id":124,
"text":"Games",
"checked":true
}]
},{
"id":13,
"text":"index.html"
},{
"id":14,
"text":"about.html"
},{
"id":15,
"text":"welcome.html"
}]
}]

创建一个指令“comboTreeDirective”并将该指令作为属性添加到组合树元素

app.directive('comboTreeDirective', function(treeData){
return {
restrict: 'A',
link: function($scope, $elem, $attr){
treeData.getData().success(function(response){
$elem.combotree('loadData', response);
});
}
}
});

使用如下所示的指令

<input class="easyui-combotree" data-options="required:true" style="width:200px;" combo-tree-directive>

下面是完整的工作示例

<!DOCTYPE html>
<html ng-app='myApp'>
<head>
<meta charset="UTF-8">
<title>Basic ComboTree - jQuery EasyUI Demo</title>
<link rel="stylesheet" type="text/css" href="themes/default/easyui.css">
<link rel="stylesheet" type="text/css" href="themes/icon.css">
<link rel="stylesheet" type="text/css" href="vendor/demo.css">
<script type="text/javascript" src="vendor/jquery.min.js"></script>
<script type="text/javascript" src="vendor/jquery.easyui.min.js"></script>
<script type="text/javascript" src="vendor/angular/angular.js"></script>
</head>
<body ng-controller="comboTreeCtrl">
<h2>Basic ComboTree</h2>
<p>Click the right arrow button to show the tree panel.</p>
<div style="margin:20px 0"></div>
<input class="easyui-combotree" data-options="required:true" style="width:200px;" combo-tree-directive>

<script type="text/javascript">


var app = angular.module('myApp',[]);
app.controller('comboTreeCtrl', function ($scope, $http){

});

app.service('treeData', ['$http',function($http){
this.getData = function(){
return $http.get('tree_data1.json');
}
}]);

app.directive('comboTreeDirective', function(treeData){
return {
restrict: 'A',
link: function($scope, $elem, $attr){
treeData.getData().success(function(response){
$elem.combotree('loadData', response);
});
}
}
});
</script>
</body>
</html>

关于javascript - 如何使用 jeasyui 将 $scope.mydata 以 Angular 绑定(bind)到数据选项?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32241130/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com