小编JSA*_*ict的帖子

如何使用javascript或jquery为json添加键和值

我有一个像这样的json变量

var jsondata={"all":"true"}
Run Code Online (Sandbox Code Playgroud)

我想将另一个键和值推送到jsondata.之后我的jsondata必须像这样.

{"all":"true","FDamount":"false","DDamount":"true"}
Run Code Online (Sandbox Code Playgroud)

怎么做???我试过jsondata.push({"FDamount":"false"})和jsondata.push("FDamount:false").这两种方法都不起作用.

谢谢

javascript json

21
推荐指数
2
解决办法
5万
查看次数

如何为angularjs中的ng-model动态赋值?

在这里,我使用ng-repeateg 动态生成一个html元素

<div ng-repeat="type in types">
    <input  type="checkbox" ng-model="{{type}}" />{{ type }}
</div>
Run Code Online (Sandbox Code Playgroud)

我想设置ng-model的类型值.是否有可能,或者我想为这样的ng-true-value设置该类型值

<div ng-repeat="type in types">
    <input  type="checkbox" ng-model="{{type}}" ng-true-value="{{type}}" />{{ type }}
</div>
Run Code Online (Sandbox Code Playgroud)

angularjs

17
推荐指数
2
解决办法
3万
查看次数

在angularjs服务中编写函数

我想在angularjs服务中编写一个函数,我想在我的所有内容中重用它

控制器.

var mod= angular.module('myapp', ['eventFilters', 'highlight', 'event', 'dayfilter', 'Services']).
config(['$routeProvider', function($routeProvider) {
$routeProvider.
      when('/', {templateUrl: 'template.html',   controller: Ctrl}).
      when('/temp', {templateUrl: 'temp.html',   controller: tempCtrl}).
      otherwise({redirectTo: '/invalid'});
}]);
mod.service ('sharedService', function() {
function daysInMonth(month,year) {
    return new Date(year, month+1,0).getDate();
}
});
Run Code Online (Sandbox Code Playgroud)

我想在我的任何控制器中使用daysInMonth函数.可能吗?如果有的话,任何人都可以用小提琴中的一些例子简要地解释我

提前致谢

angularjs

13
推荐指数
3
解决办法
3万
查看次数

如何使用css基于另一个div动态更改div的高度?

这是我的代码

HTML:

<div class="div1">
  <div class="div2">
    Div2 starts <br /><br /><br /><br /><br /><br /><br /> Div2 ends
  </div>
  <div class="div3">
    Div3
  </div>
</div> 
Run Code Online (Sandbox Code Playgroud)

CSS:

.div1 {
  width: 300px;
  height: auto;
  background-color: grey;
  border: 1px solid;
  overflow: auto;
}

.div2 {
  width: 150px;
  height: auto;
  background-color: #F4A460;
  float: left;
}

.div3 {
  width: 150px;
  height: auto;
  background-color: #FFFFE0;
  float: right;
}
Run Code Online (Sandbox Code Playgroud)

我想动态增加div3的高度.

例如,如果div1的高度是500px,那么div3的高度应该是500px.我知道我可以使用继承,但事情是div1的高度是自动,所以它不会帮助.这是我的小提琴http://jsfiddle.net/prashusuri/E4Zgj/1/怎么做?

谢谢

html css

13
推荐指数
2
解决办法
9万
查看次数

错误:使用警报时,angularjs中的$ digest已在进行中

我只是从控制器中的服务获取json数据.

我正在使用回调函数在加载时打印成功消息.它工作正常,但它也抛出了我在问题中提到的错误

//JSON file
{
"pc":"name"
}

// angular services
var service = angular.module('Services', ['ngResource']).
factory('Widgets', function($resource){
    return $resource('/json/home.json', {}, {
        query: {method:'GET', params:{}, isArray:false}
    });
});

//controller
function editWidget($scope, Widgets) {
 $scope.data = Widgets.query(function(data) {   
    alert("Success Data Loaded ---> " + JSON.stringify(data.pc));
 });
}
Run Code Online (Sandbox Code Playgroud)

angularjs

10
推荐指数
2
解决办法
4882
查看次数

客户端发送的请求在语法上是不正确的().+ Spring,RESTClient

我正在使用JSON对象使用Spring MVC.当我想从RESTClient发送JSON对象时,我得到了

HTTP状态400 - 客户端发送的请求语法错误().

这是我的控制器

ObjectMapper mapper=new ObjectMapper();
@RequestMapping(value = "/addTask", method = RequestMethod.GET)
       public ModelAndView addTask(@RequestParam("json") String json) throws JsonParseException, JsonMappingException, IOException 
       {
          System.out.println("Json object from REST : "+json);
          Task task=(Task) mapper.readValue(json, Task);
          service.addService(task);
          return new ModelAndView("Result");
       }
Run Code Online (Sandbox Code Playgroud)

我的请求网址: http://localhost:8080/Prime/addTask

我的Json对象:

{"taskName":"nothing","taskId":1234,"taskDesc":"什么都没做"}

我也尝试在RESTClient中指定"Content-Type:application/json"但仍然得到相同的错误

spring json rest-client

8
推荐指数
2
解决办法
2万
查看次数

如何使用angularJS restful服务从外部文件中使用json数据

我正在开发一个应用程序.我正在从中检索json数据

外部文件使用$ http.get()方法,它工作正常.现在我想尝试使用角度

宁静的服务.它在过滤器中工作正常,但当我在控制器中使用它时

显示未定义.

//Service.js File
angular.module('calenderServices', ['ngResource']).
factory('Events', function($resource){
return $resource('/EventCalender/:File.json', {}, {
query: {method:'GET', params:{File:'events'}, isArray:true}
});
});


        //This is my app Module
angular.module('calender', ['eventFilters','highlight','event','calenderServices']).
config(['$routeProvider', function($routeProvider) {
$routeProvider.
  when('', {templateUrl: 'template.html',   controller: MonthCtrl}).
  otherwise({redirectTo: '/invalid'});
}]);


     //This is my filter.js
angular.module('eventFilters', ['calenderServices']).filter('compare', function(Events) {
var events=Events.query();
alert(events[0].name); //it is displaying the name "Milestone1" });


     //This is my controller.
function MonthCtrl($scope, Events){
var events=Events.query();
    alert(events[0].name); //it is displaying undefined
    }

     //whenever i try to use the variable …
Run Code Online (Sandbox Code Playgroud)

angularjs

6
推荐指数
1
解决办法
7042
查看次数

如何使函数等待异步调用完成?

我有一项angularjs服务来获取我的json数据.

// Controller.js file
$scope.data=Events.query();

$scope.getEventtypes = function(){
    angular.forEach($scope.data,function(value, key){
        var arr = [];
        if(key==$scope.month+$scope.year)  {
            for(var i=0; i<key.length; i++) {
                arr.push(value[i].type);
                $scope.eventtypes=arr.unique();
            }
        }
    });
};
Run Code Online (Sandbox Code Playgroud)

在尝试访问value[i].type它时抛出错误无法读取type未定义的属性.我知道这是因为异步调用.

//i want to add success function like this
$http.get('').success(function(data) {
....
});
Run Code Online (Sandbox Code Playgroud)

谁能帮我??如果你建议做一些比这更有效的事情会更好.谢谢

angularjs

3
推荐指数
1
解决办法
3万
查看次数

标签 统计

angularjs ×5

json ×2

css ×1

html ×1

javascript ×1

rest-client ×1

spring ×1