草庐IT

读取数据

全部标签

javascript - 无法读取未定义的 angular2 ngif 的属性

我现在可以在View中获取对象,但是我无法运行if语句。根据之前的回答,这就是我引入对象的方式。publicgetPosts$(category,limit){returnthis.cartService.getPosts(category,limit).map(response=>{returnresponse&&response.data&&response.data.children;};}ngOnInit(){this.getPosts$(this.category,this.limit).subscribe(cart=>{this.cart=cart;}}我正在尝试运行,但无

javascript - 在过滤器方法中访问 vue 实例/数据

我正在尝试像这样访问过滤器函数内的vue实例数据。JS:-newVue({data:{amount:10,exchangeRate:50},el:"#app",filters:{currency:function(amount){console.log(this);//returnamount*this.exchangeRate;returnamount*50;}}})HTML:{{amount|currency}}我的目标是使用returnamount*this.exchangeRate;但是this等于window这里。我怎样才能做到这一点?谢谢。jsfiddle

javascript - 我如何从 JSON 数据递归创建 UL/LI - 多层深度

我正在尝试使用以下JSON数据在递归内部函数中创建以下类似结构,运气不佳,确实需要一些帮助,所以如果有人可以提供帮助,请提供帮助。提前谢谢你。....etc我使用的JSON数据如下:varJSON={menu:[{id:'0',sub:[{name:'loremipsum0-0',link:'0-0',sub:null},{name:'loremipsum0-1',link:'0-1',sub:null},{name:'loremipsum0-2',link:'0-2',sub:null}]},{id:'1',sub:null},{id:'2',sub:[{name:'loremips

javascript - 当一个对象从另一个对象复制时,为什么 Angular 不数据绑定(bind)数据?

我创建了一个简单的jsfiddle来说明我的问题:fiddleHTML:{{p.id}}:{{p.name}}Javascript:varmyApp=angular.module('myApp',[]);functionMyCtrl($scope){varproducts=[{id:1,name:'first'},{id:2,name:'second'}];$scope.products=products;varprod={id:3,name:'third'};$scope.overwrite=function(p){p.id=4;p.name='forth';p=prod;//thi

javascript - 通过客户端javascript读取txt文件

我是javascript的新手,正在尝试将一个txt文件打开到var中,然后将其注入(inject)到htmldiv中...我尝试使用fopen但没有成功。file=fopen(getScriptPath("info.txt"),0);file_length=flength(file);varcontent=fread(file,file_length);vardiv=document.getElementById("myDiv");//alert(div);div.innerHTML="";div.innerHTML=content; 最佳答案

javascript - 从 Kendo Treeview 中读取选定节点的值?

我有一个KendoTreeview,它有一个带有{id,value}的节点。我想在单击按钮时获取选定节点的ID和值。我怎样才能得到它?是否有任何内置函数可以获取它?这是我的示例代码:$("mytree").kendoTreeView({dataSource:mydata,dataTextField:"Name",dataValueField:"Id",}); 最佳答案 使用.select()方法。请务必查看其他可用的方法。vartv=$('.mytree').data('kendoTreeView'),selected=tv.sel

javascript - Angular4 - 将表单数据发布到 rest api

如何将表单数据发布到外部restapi?目前我有一个html表单:Save然后我在component.ts文件中有处理提交的函数:onSubmit=function(user){console.log(user);//this.http.post('http://xxx/externalapi/add',user);}但是如何将表单数据发布到我的外部api?用angular发送表单数据的标准是什么?它只是一个带有表单数据作为queryParams的简单发布请求,还是将其转换为JSON的标准。我可以修改API来处理发送的任何数据,所以这不是问题。 最佳答案

javascript - 从 jquery 访问 json 数据

我正在使用jQuery1.4.2创建一个ajax应用程序,我尝试使用get()、post()和ajax()方法本身。我的php服务返回:[{"k":"label0","v":0.5},{"k":"label1","v":99.43},{"k":"label2","v":2.46},{"k":"label3","v":46.29},{"status":"OK"}]在我的成功回调中,我尝试访问json.status和json[0][0]但它总是返回“未定义”。我做错了什么?functiongetSysinfo(source){varjson=null;$.ajax({url:source,

javascript - 在 ExtJS 中,如何向数据网格行添加自定义 CSS 类?

如何将自定义CSS类添加到数据网格(Ext.grid.Panel)中的行?我正在使用ExtJS4.0。 最佳答案 实现方式是在网格上定义viewConfig:Ext.create('Ext.grid.Panel',{...viewConfig:{getRowClass:function(record,index,rowParams,store){returnrecord.get('someattr')==='somevalue')?'someclass':'';}},...}); 关于j

javascript - Vue.js: 从 "parent"Vue 获取数据

我有一个(不可更改的)DOM结构如下:.........还有两个js文件:index.js:varchild=require('childVue');module.exports=newVue({el:'#indexVue',...});childVue.js:module.exports=newVue({el:'#childVue',methods:{something:function(){//Parentdataneededhere...},...}});如图所示,我需要indexVue的数据在childVue.有什么办法可以传递给它吗?我试图将它传递给带有(v-on="clic