gpt4 book ai didi

javascript - Sencha Touch 模型中的字段转换功能失败

转载 作者:行者123 更新时间:2023-11-28 09:18:30 24 4
gpt4 key购买 nike

我正在制作 Sencha Touch PhoneGap 应用程序。我正在尝试将具有转换功能的字段添加到 Sencha Touch 2.1 中的模型中此转换函数应该查找单个字母并替换它们(“convFAF”)。

我不明白为什么它会失败。

该功能到位后,使用该模型的列表(列出商店)将显示为空白。 Xcode 不会将任何错误消息打印到控制台。

我的模型:

Ext.define('Labblistan.model.LabItem', {
extend: 'Ext.data.Model',
config: {
fields: [
{name: 'Group', type: 'String'},
{name: 'Groupname', type: 'String'},
{name: 'Analysis', type: 'String'},
{name: 'Sex', type: 'String'},
{name: 'AgeFrom', type: 'String'},
{name: 'AgeTo', type: 'String'},
{name: 'LowLimit', type: 'String'},
{name: 'UpperLimit', type: 'String'},
{name: 'Unit', type: 'String'},
{name: 'Comment', type: 'String'},
{name: 'SortOrder', type: 'String'},
{
name : 'formattedAnalysis',
type : 'string',
convert : function(v, record) {
var unformattedAnalysis = record.get('Analysis');
if (unformattedAnalysis.indexOf("-") != -1) {
return unformattedAnalysis.substring(unformattedAnalysis.indexOf("-")).substr(1).toUpperCase();
} else {
return unformattedAnalysis.toUpperCase();
}
}},
{name: 'formattedAgeFrom', convert: convertAgeFrom},
]
},
});
function convertAgeFrom(v, record) {
var unformattedAgeFrom = record.get('AgeFrom');
var formattedAgeFrom = unformattedAgeFrom.replace('d', ' d.').replace('y', ' år').replace('m', ' mån.').replace('w', ' v.');
return formattedAgeFrom;
}

正如你所看到的,我已经有了一个转换函数(“formattedAnalysis” - 工作正常)。

我尝试在字段定义中使用该函数(根据 formattedAnalysis),但结果相同。我还尝试将 AgeFrom 类型设置为 Auto (以及 formattedAgeFrom 的 auto 和 string

最奇怪的部分是,如果我切换 record.get('AgeFrom');到“分析”,该功能起作用。它似乎也适用于 Group、Unit 和 SortOrder,但不适用于 AgeFrom 或 AgeTo(我现在有兴趣转换这两个字段)。

数据是从 XML 文件加载的,可以在 here 找到该文件的副本

我认为添加此转换很容易,但我在这里完全不知所措。非常感谢任何帮助或想法。

最佳答案

所以,显然当使用 Xcode + PhoneGap + Sencha 时,你不会得到与浏览器中相同的控制台输出。这让我错过了真正导致问题的原因。

Uncaught TypeError: Cannot call method 'replace' of undefined 

所以只要检查字段不为空就可以解决它:

function convertAgeFrom(v, record) {
var unformattedAgeFrom = record.get('AgeFrom');
if (unformattedAgeFrom != null) {
var formattedAgeFrom = unformattedAgeFrom.replace('d', ' d.').replace('y', ' år').replace('m', ' mån.').replace('w', ' v.');
return formattedAgeFrom;
}
}

感谢 ThinkFloyd 请求错误消息。不会想到要检查其他情况。 (虽然我的项目当前状态无法在浏览器中运行,但我有一个早期的原型(prototype),它足够接近以引发相同的错误,有人知道是否有办法向 xcode 控制台获取更多信息?)

关于javascript - Sencha Touch 模型中的字段转换功能失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15311195/

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