【发布时间】:2015-12-20 08:56:55
【问题描述】:
我有以下型号:
Ext.define('myApp.model.tool.SpecialModel', {
extend: 'Ext.data.Model',
fields: [
{name: 'id', type: 'string'},
{name: 'loginName', type: 'string'},
{name: 'firstName', type: 'string'},
{name: 'lastName', type: 'string'},
],
proxy: {
type: 'rest',
url: '/special/url',
reader: {
type: 'json'
}
}
});
还有这个 ViewModel:
Ext.define('myApp.view.support.MySpecialViewModel', {
extend: 'Ext.app.ViewModel',
alias: 'viewmodel.myspecial',
stores: {
session: {
model: 'myApp.model.tool.SpecialModel'
}
}
});
还有这个观点:
Ext.define('myApp.view.support.MySpecialView', {
extend: 'Ext.toolbar.Toolbar',
viewModel: 'myspecial',
config: {
items: [
{
xtype: 'button',
bind: '{session.lastName}',
menu: [
{
text: 'My Profile',
handler: 'onProfileClick'
}
]
}
]
},
});
在渲染视图时,商店已经被填满。 为什么按钮不显示指定 ViewModel 的 lastName? 当我尝试使用内联数据时,它可以工作。
提前致谢。
编辑:当我将按钮绑定更改为以下内容时
...
xtype: 'button',
bind: 'Hello, {session.lastName}',
menu: [
{
text: 'My Profile',
handler: 'onProfileClick'
}
]
...
甚至不显示硬编码的字符串。我在这里错过了什么?
编辑2:
这是我的 json 数据:
{
"privileges": {
"privManageCustomer": true,
"privManageCustomerAccount": true,
},
"user": {
"accountLocked": false,
"accountLockedAt": null,
"customerId": "12123213213123",
"email": "213213",
"failedLogins": 0,
"firstName": null,
"id": "123678213621783",
"languageId": "de",
"lastFailedLogin": null,
"lastLogin": null,
"lastName": "Whatever",
"loginName": "test123"
}
}
【问题讨论】:
-
你能把url的json样本发给我们吗:'/special/url',还有一个小提琴会更好
-
@KalaiarasanManimaran 添加了我的数据。
-
我不太确定绑定是否可以通过这种方式完成。但无论如何,首先你错过了阅读器的 rootProperty 配置,所以阅读器不知道从什么json的一部分来获取数据。 rootProperty 应该等于“用户”。其次 - 我永远不会将我的商店或数据元素命名为“会话”,而它可以与保留的会话对象相关联。如果仍然不起作用,请尝试绑定到 {session.data.items.0.lastName}。
标签: javascript extjs mvvm extjs6