- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试为我的学校项目构建一个简单的用户设置功能。<br/>我创建了一个这样的数据模型:
Ext.define('Urlopy.Model.UserPreferences', {
extend : 'Ext.data.Model',
idProperty : 'userID',
fields : [{
name : 'userID',
type : 'string'
}, {
name : 'admin',
type : 'bool'
}]
});
像这样的商店:
Ext.define('Urlopy.Store.UserPreferences', {
extend : "Ext.data.Store",
autoLoad : false,
autoSync : true,
batch : false,
proxy : {
type : 'ajax',
sortParam : undefined,
startParam : undefined,
pageParam : undefined,
limitParam : undefined,
noCache : false,
headers : {
"Content-Type" : "application/json; charset=utf-8"
},
api : {
read : 'services/UserPreferences.asmx/Get',
update : 'services/UserPreferences.asmx/Update'
},
reader : {
type : 'json',
root : 'd.data'
},
writer : {
type : 'json',
encode : false,
writeAllFields : true,
root : 'data'
}
},
model : 'Urlopy.Model.UserPreferences'
});
在我的应用程序中,当用户登录时,我想获得他的偏好。
我有这样一个功能:
onLogin : function() {
this.createGlobalStores();
this.userPreferenceStore.load({
callback : function(r, options, success) {
console.log(r.data)
}
});
},
createGlobalStores : function() {
this.userPreferenceStore = Ext.create("Urlopy.Store.UserPreferences");
},
我想在回调中做的是获取用户 ID 并显示它,甚至使用简单的警报。
现在我得到的只是在 Firebug 中显示的未定义。
我来自服务器的 json 数据如下所示:
{"d":{"__type":"Urlopy.services.UserPreference","userID":"12445","admin":true}}
我需要能够在该商店上调用加载方法,并在回调中从模型中获取特定属性。我的商店将始终有 1 件商品! (还有其他方法吗?)
欢迎提出任何关于为什么这不起作用的想法!
编辑我已经更改了我的服务器脚本以像这样返回 json:
{"d":{"data":{"userID":"12-44-55","admin":true}}}
这很好用,不需要在对象周围添加额外的 []。
最佳答案
首先,商店的加载需要一个数组,其次,您将代理的根设置错误。因为你的 json 中没有 d.data 对象。简单的解决方法是将您的 json 数据编码为一个包含一个元素的数组,并将该数组的标记为“数据”...
{"d":[{"__type":"Urlopy.services.UserPreference","userID":"12445","admin":true}]}
然后将根设置为d
reader : {
type : 'json',
root : 'd'
}
在此回调之后,您将拥有一组记录,其中包含一个元素,您可以使用索引 0 轻松访问该元素
callback : function(records, options, success) {
console.log(records[0].data.userID +" " + records[0].data.admin);
}
编辑
其他不涉及商店的方法
做一个简单的 ajax 请求,例如:
Ext.Ajax.request({
url: 'services/UserPreferences.asmx/Get',
params: {/*if you want any extra params to be sent*/},
scope: this,
success: function (result) {
var response = Ext.decode(result.responseText);
//this is for your initial json
alert(response.d.userID);
},
failure: function (result) {
alert('something failed')
}
});
我不知道您对数据做了什么,但是例如您可以将其加载到表单中,对于更新方法,您将拥有表单的提交选项。可以配置发送数据的 url。
关于json - Ext JS 4 存储加载回调,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11014509/
图书馆 EXT-JS 、 EXT-CORE 、 EXT-GWT 之间有什么区别,因为我在 ext-js 上工作所以请用外行语言解释我:) 最佳答案 最初它只是 Ext JS。作为 3.x 的一部分,E
我在 Ext 窗口中有 Ext GridPanel。为了使 Ext Window Resizeable,我将它的属性设置为 true 并且它工作正常。 但是,还想让网格可以调整大小。因此,为此我也尝试
我想构建一个网络应用程序。每当我在 Linux 终端发出命令时 $ sencha app build 在构建应用程序时,我遇到了一些与依赖相关的问题。错误类似于 Failed to resolv
我正在开发一个由 domain.ext 提供的网络应用程序。此 Web 应用程序使用基于 cookie 的 session ,并为用户提供在子域上托管包含自定义 JavaScript 的网页的能力,例
我正在尝试设置 LAMP使用 docker 的 web 服务器,很高兴发现 php 上的好人已经放在一起了a docker container for php . 通过阅读文档,我发现了三个表面上可以
美好的一天,伙计们, 我知道这听起来像是一个愚蠢的问题。但是,我想知道是否有人可以向我解释之间的区别。外网和 EXT.JS .. 我一直试图理解它们,但结果为零。据我所知,EXT.NET集成了EXT.
与常规 Ext.ajax 调用相比,Ext.direct 的主要优点是什么?我什么时候应该考虑使用一种而不是另一种? 最佳答案 实际上,这取决于您的后端、您想要做什么以及适合您的情况。你提出的问题相当
Ext.extend 和 Ext.override 有什么区别?在java中,你扩展一个类并覆盖它的方法。但是看看语法,似乎在 extjs 中,你既可以扩展一个类,也可以覆盖一个类 最佳答案 Ext.
我是 Ext Js 新手。我有以下文件结构。 我正在测试以下代码 - First Ext Js Page
我正在使用修改后的kanderson-well beats委托版本来修改AVKit需要的请求。所有代码将在帖子的底部。修改请求、创建字幕播放列表并将它们添加到主播放列表中是很好的,因为它们在请求AVM
我无法使用 Ext.namespace() 访问对象。 返回错误类型错误:Company.Test 不是函数 一直在查看文档但仍然无法使用对象。 这是命名空间脚本 Ext.namespace('Com
首先,我的问题是我想知道 Ext.Define() 和 Ext.Create() 之间有什么不同, 我想知道如何以正确的方式使用它们。 我查看了我的代码和许多 Extjs4 MVC 教程, 我在 Ex
我们正在使用 ext.net 版本 5.2.0,据我了解,它包括 Ext JS 7.2.0.67。我正在使用看起来像这样的 slider 控件 ext.net 5.2 Slider: https://
我刚刚使用 Ext JS 和 Ext Gantt 技术在我们的 .NET (WebForms) 项目中完成了甘特图页面的开发。正如我在之前的 post 中所述,效果很好。 我现在的问题是,与 hte
在我的 ExtJS 4.0.7 应用程序中,我需要动态加载一些第 3 方 javascript,以呈现某些面板内容(一些精美的图表/可视化小部件)。 我遇到了一个古老的问题,即在我尝试使用它之前脚本没
使用 ext-all.js 和 ext-all-debug.js 有什么区别? 从 debug.js 更改为 ext-all.js 会提高性能吗? 我可以假设从调试切换到普通文件不会对应用程序产生任何
我是在服用疯狂的药丸,还是这两件事几乎相同? 最佳答案 在这一点上花了大量时间使用这两个框架后,我会说它们并不“非常相同”。虽然它们可能都使用相同的图形 Assets ,但它们实现的方式却大不相同,并
我正在使用 Ext.form.Panel ,其配置如下: defaultType : 'textfield', layout : 'auto', height : '60%', w
我想重写 this从 Ext3 到 Ext4 的教程。但是从我能够观察到的情况来看,createDelegate 函数已被删除(可能与许多其他事情一样)并且它不起作用。我试过调用 call/apply
目标: 仅在需要时加载 Ext 框架(JS 文件)。 问题: 在稍后的状态下加载 Ext.JS 时,Ext.onReady 不会触发。我试着解决 Ext.onReady,但我也没有开始工作。我很高兴有
我是一名优秀的程序员,十分优秀!