Titanium / Appcelerator:使用iOS.Toolbar的ListView TextField添加“完成”按钮

时间:2016-04-15 14:22:28

标签: ios listview appcelerator textfield appcelerator-titanium

我发现的第一个问题是在TextField中定义KeyboardToolbar不能在ListView(Ti SDK 5.2.2)中工作。

下面的内容无法编译:

listView.xml:

<Alloy>
<View id="main" layout="vertical">
    <ListView id="myListView" height="Ti.UI.SIZE">
        <Templates>
            <ItemTemplate id="itemTemplate" name="template1">
                <TextField class="textField" onBlur="onBlur" onChange="onChange" onFocus="onFocus" bindId="textField1">
                    <KeyboardToolbar>
                        <Toolbar platform="ios" bindId="toolbar1">
                            <Items>
                                <Button bindId="done1" onClick="onClick" style="Ti.UI.iPhone.SystemButtonStyle.DONE">Done</Button>
                            </Items>
                        </Toolbar>
                    </KeyboardToolbar>
                </TextField>
            </ItemTemplate>
        </Templates>
        <ListSection></ListSection>
    </ListView>
</View>
</Alloy>

listView.tss:

".textField": {
  left: 10,
  textAlign: Titanium.UI.TEXT_ALIGNMENT_LEFT,
  width: 150,
  editable: true,
  borderColor: "blue",
  height: 55,
  keyboardType: Ti.UI.KEYBOARD_TYPE_NUMBER_PAD,
  returnKeyType: Ti.UI.RETURNKEY_DONE,
}

listView.js:

function onFocus(event) {
    Ti.API.info("onFocus");
}

function onBlur() {
    Ti.API.info("onBlur");
}

function onChange() {
    Ti.API.info("onChange");
}

function onClick() {
    Ti.API.info("onClick");
}

$.myListView.getSections()[0].setItems([{
    "template": "template1",
    "textField1": {
        value: "Test"
    }
},
{
    "template": "template1",
    "textField1": {
        value: "Test2"
    }
}]);

有没有人知道如何在“完成”按钮上捕捉点击事件并模糊()TextField?

错误堆栈:

----- MVC GENERATION -----
[INFO]  [app.tss] global style processing...
[INFO]  [global style] writing to cache...
[INFO]  [index.xml] view processing...
[INFO]    style:      "index.tss"
[INFO]    view:       "index.xml"
[INFO]    controller: "index.js"
[TRACE] - Processing "builtins" module...
[TRACE] - Processing "optimizer" module...
[TRACE] - Processing "compress" module...
[INFO]    created:    "Resources/iphone/alloy/controllers/index.js"
[DEBUG]   map:        "build/map/Resources/iphone/alloy/controllers/index.js.map"
[INFO]    created:     "Resources/iphone/alloy/styles/index.js"
[INFO]  [listView.xml] view processing...
[INFO]    style:      "listView.tss"
[INFO]    view:       "listView.xml"
[DEBUG] /Users/ceck/.appcelerator/install/5.2.2/package/node_modules/alloy/Alloy/commands/compile/parsers/Alloy.Abstract._ItemArray.js:62
[DEBUG]                             return state.itemsArray + '.push(' + s.parent.symbol + ');';
[DEBUG]                                                                          ^
[DEBUG] TypeError: Cannot read property 'symbol' of undefined
[DEBUG]     at Object.CU.generateNodeExtended.post (/Users/ceck/.appcelerator/install/5.2.2/package/node_modules/alloy/Alloy/commands/compile/parsers/Alloy.Abstract._ItemArray.js:62:52)
[DEBUG]     at Object.exports.parse (/Users/ceck/.appcelerator/install/5.2.2/package/node_modules/alloy/Alloy/commands/compile/parsers/base.js:14:17)
[DEBUG]     at Object.exports.parse (/Users/ceck/.appcelerator/install/5.2.2/package/node_modules/alloy/Alloy/commands/compile/parsers/default.js:10:27)
[DEBUG]     at parse (/Users/ceck/.appcelerator/install/5.2.2/package/node_modules/alloy/Alloy/commands/compile/parsers/Ti.UI.Button.js:30:30)
[DEBUG]     at Object.exports.parse (/Users/ceck/.appcelerator/install/5.2.2/package/node_modules/alloy/Alloy/commands/compile/parsers/base.js:11:17)
[DEBUG]     at Object.exports.parse (/Users/ceck/.appcelerator/install/5.2.2/package/node_modules/alloy/Alloy/commands/compile/parsers/Ti.UI.Button.js:14:27)
[DEBUG]     at Object.exports.generateNode (/Users/ceck/.appcelerator/install/5.2.2/package/node_modules/alloy/Alloy/commands/compile/compilerUtils.js:332:48)
[DEBUG]     at Object.exports.generateNodeExtended (/Users/ceck/.appcelerator/install/5.2.2/package/node_modules/alloy/Alloy/commands/compile/compilerUtils.js:269:17)
[DEBUG]     at /Users/ceck/.appcelerator/install/5.2.2/package/node_modules/alloy/Alloy/commands/compile/parsers/Alloy.Abstract._ItemArray.js:59:16
[DEBUG]     at Array.forEach (native)
[DEBUG]     at Function._.each._.forEach (/Users/ceck/.appcelerator/install/5.2.2/package/node_modules/alloy/Alloy/lib/alloy/underscore.js:79:11)
[DEBUG]     at parse (/Users/ceck/.appcelerator/install/5.2.2/package/node_modules/alloy/Alloy/commands/compile/parsers/Alloy.Abstract._ItemArray.js:41:4)
[DEBUG]     at Object.exports.parse (/Users/ceck/.appcelerator/install/5.2.2/package/node_modules/alloy/Alloy/commands/compile/parsers/base.js:11:17)
[DEBUG]     at Object.exports.parse (/Users/ceck/.appcelerator/install/5.2.2/package/node_modules/alloy/Alloy/commands/compile/parsers/Alloy.Abstract._ItemArray.js:18:27)
[DEBUG]     at Object.exports.parse (/Users/ceck/.appcelerator/install/5.2.2/package/node_modules/alloy/Alloy/commands/compile/parsers/Alloy.Abstract.Items.js:16:48)
[DEBUG]     at Object.exports.generateNode (/Users/ceck/.appcelerator/install/5.2.2/package/node_modules/alloy/Alloy/commands/compile/compilerUtils.js:332:48)
[DEBUG]     at Object.exports.generateNodeExtended (/Users/ceck/.appcelerator/install/5.2.2/package/node_modules/alloy/Alloy/commands/compile/compilerUtils.js:269:17)
[DEBUG]     at /Users/ceck/.appcelerator/install/5.2.2/package/node_modules/alloy/Alloy/commands/compile/parsers/Alloy.Abstract._ItemContainer.js:51:15
[DEBUG]     at Array.forEach (native)
[DEBUG]     at Function._.each._.forEach (/Users/ceck/.appcelerator/install/5.2.2/package/node_modules/alloy/Alloy/lib/alloy/underscore.js:79:11)
[DEBUG]     at parse (/Users/ceck/.appcelerator/install/5.2.2/package/node_modules/alloy/Alloy/commands/compile/parsers/Alloy.Abstract._ItemContainer.js:31:4)
[DEBUG]     at Object.exports.parse (/Users/ceck/.appcelerator/install/5.2.2/package/node_modules/alloy/Alloy/commands/compile/parsers/base.js:11:17)
[DEBUG]     at Object.exports.parse (/Users/ceck/.appcelerator/install/5.2.2/package/node_modules/alloy/Alloy/commands/compile/parsers/Alloy.Abstract._ItemContainer.js:20:27)
[DEBUG]     at Object.exports.parse (/Users/ceck/.appcelerator/install/5.2.2/package/node_modules/alloy/Alloy/commands/compile/parsers/Ti.UI.iOS.Toolbar.js:11:52)
[DEBUG]     at Object.exports.generateNode (/Users/ceck/.appcelerator/install/5.2.2/package/node_modules/alloy/Alloy/commands/compile/compilerUtils.js:332:48)
[DEBUG]     at Object.exports.generateNodeExtended (/Users/ceck/.appcelerator/install/5.2.2/package/node_modules/alloy/Alloy/commands/compile/compilerUtils.js:269:17)
[DEBUG]     at /Users/ceck/.appcelerator/install/5.2.2/package/node_modules/alloy/Alloy/commands/compile/parsers/_ProxyProperty.js:43:14
[DEBUG]     at Array.forEach (native)
[DEBUG]     at Function._.each._.forEach (/Users/ceck/.appcelerator/install/5.2.2/package/node_modules/alloy/Alloy/lib/alloy/underscore.js:79:11)
[DEBUG]     at parse (/Users/ceck/.appcelerator/install/5.2.2/package/node_modules/alloy/Alloy/commands/compile/parsers/_ProxyProperty.js:32:4)
[DEBUG]     at Object.exports.parse (/Users/ceck/.appcelerator/install/5.2.2/package/node_modules/alloy/Alloy/commands/compile/parsers/base.js:11:17)
[DEBUG]     at Object.exports.parse (/Users/ceck/.appcelerator/install/5.2.2/package/node_modules/alloy/Alloy/commands/compile/parsers/_ProxyProperty.js:16:27)
[DEBUG]     at Object.exports.parse (/Users/ceck/.appcelerator/install/5.2.2/package/node_modules/alloy/Alloy/commands/compile/parsers/_ProxyProperty.KeyboardToolbar.js:12:37)
[DEBUG]     at Object.exports.generateNode (/Users/ceck/.appcelerator/install/5.2.2/package/node_modules/alloy/Alloy/commands/compile/compilerUtils.js:332:48)
[DEBUG]     at Object.exports.generateNodeExtended (/Users/ceck/.appcelerator/install/5.2.2/package/node_modules/alloy/Alloy/commands/compile/compilerUtils.js:269:17)
[DEBUG]     at /Users/ceck/.appcelerator/install/5.2.2/package/node_modules/alloy/Alloy/commands/compile/parsers/Ti.UI.TextField.js:60:14
[DEBUG]     at Array.forEach (native)
[DEBUG]     at Function._.each._.forEach (/Users/ceck/.appcelerator/install/5.2.2/package/node_modules/alloy/Alloy/lib/alloy/underscore.js:79:11)
[DEBUG]     at parse (/Users/ceck/.appcelerator/install/5.2.2/package/node_modules/alloy/Alloy/commands/compile/parsers/Ti.UI.TextField.js:30:4)
[DEBUG]     at Object.exports.parse (/Users/ceck/.appcelerator/install/5.2.2/package/node_modules/alloy/Alloy/commands/compile/parsers/base.js:11:17)
[DEBUG]     at Object.exports.parse (/Users/ceck/.appcelerator/install/5.2.2/package/node_modules/alloy/Alloy/commands/compile/parsers/Ti.UI.TextField.js:20:27)
[DEBUG]     at Object.exports.generateNode (/Users/ceck/.appcelerator/install/5.2.2/package/node_modules/alloy/Alloy/commands/compile/compilerUtils.js:332:48)
[DEBUG]     at Object.exports.generateNodeExtended (/Users/ceck/.appcelerator/install/5.2.2/package/node_modules/alloy/Alloy/commands/compile/compilerUtils.js:269:17)
[DEBUG]     at /Users/ceck/.appcelerator/install/5.2.2/package/node_modules/alloy/Alloy/commands/compile/parsers/Alloy.Abstract.ItemTemplate.js:64:15
[DEBUG]     at Array.forEach (native)
[DEBUG]     at Function._.each._.forEach (/Users/ceck/.appcelerator/install/5.2.2/package/node_modules/alloy/Alloy/lib/alloy/underscore.js:79:11)
[DEBUG]     at parse (/Users/ceck/.appcelerator/install/5.2.2/package/node_modules/alloy/Alloy/commands/compile/parsers/Alloy.Abstract.ItemTemplate.js:54:5)
[DEBUG]     at Object.exports.parse (/Users/ceck/.appcelerator/install/5.2.2/package/node_modules/alloy/Alloy/commands/compile/parsers/base.js:11:17)
[DEBUG]     at Object.exports.parse (/Users/ceck/.appcelerator/install/5.2.2/package/node_modules/alloy/Alloy/commands/compile/parsers/Alloy.Abstract.ItemTemplate.js:10:27)
[DEBUG]     at Object.exports.generateNode (/Users/ceck/.appcelerator/install/5.2.2/package/node_modules/alloy/Alloy/commands/compile/compilerUtils.js:332:48)
[DEBUG]     at Object.exports.generateNodeExtended (/Users/ceck/.appcelerator/install/5.2.2/package/node_modules/alloy/Alloy/commands/compile/compilerUtils.js:269:17)
[DEBUG]     at /Users/ceck/.appcelerator/install/5.2.2/package/node_modules/alloy/Alloy/commands/compile/parsers/Ti.UI.ListView.js:132:17
[DEBUG]     at Array.forEach (native)
[DEBUG]     at Function._.each._.forEach (/Users/ceck/.appcelerator/install/5.2.2/package/node_modules/alloy/Alloy/lib/alloy/underscore.js:79:11)
[DEBUG]     at /Users/ceck/.appcelerator/install/5.2.2/package/node_modules/alloy/Alloy/commands/compile/parsers/Ti.UI.ListView.js:123:6
[DEBUG]     at Array.forEach (native)
[DEBUG]     at Function._.each._.forEach (/Users/ceck/.appcelerator/install/5.2.2/package/node_modules/alloy/Alloy/lib/alloy/underscore.js:79:11)
[DEBUG]     at parse (/Users/ceck/.appcelerator/install/5.2.2/package/node_modules/alloy/Alloy/commands/compile/parsers/Ti.UI.ListView.js:49:4)
[DEBUG]     at Object.exports.parse (/Users/ceck/.appcelerator/install/5.2.2/package/node_modules/alloy/Alloy/commands/compile/parsers/base.js:11:17)
[DEBUG]     at Object.exports.parse
[DEBUG]  (/Users/ceck/.appcelerator/install/5.2.2/package/node_modules/alloy/Alloy/commands/compile/parsers/Ti.UI.ListView.js:30:27)
[DEBUG]     at Object.exports.generateNode (/Users/ceck/.appcelerator/install/5.2.2/package/node_modules/alloy/Alloy/commands/compile/compilerUtils.js:332:48)
[DEBUG]     at /Users/ceck/.appcelerator/install/5.2.2/package/node_modules/alloy/Alloy/commands/compile/compilerUtils.js:416:29
[DEBUG]     at Array.forEach (native)
[DEBUG]     at Function._.each._.forEach (/Users/ceck/.appcelerator/install/5.2.2/package/node_modules/alloy/Alloy/lib/alloy/underscore.js:79:11)
[DEBUG]     at Object.exports.generateNode (/Users/ceck/.appcelerator/install/5.2.2/package/node_modules/alloy/Alloy/commands/compile/compilerUtils.js:407:5)
[DEBUG]     at /Users/ceck/.appcelerator/install/5.2.2/package/node_modules/alloy/Alloy/commands/compile/index.js:777:28
[DEBUG]     at Array.forEach (native)
[DEBUG]     at Function._.each._.forEach (/Users/ceck/.appcelerator/install/5.2.2/package/node_modules/alloy/Alloy/lib/alloy/underscore.js:79:11)
[DEBUG]     at parseAlloyComponent (/Users/ceck/.appcelerator/install/5.2.2/package/node_modules/alloy/Alloy/commands/compile/index.js:771:5)
[DEBUG]     at /Users/ceck/.appcelerator/install/5.2.2/package/node_modules/alloy/Alloy/commands/compile/index.js:406:6
[DEBUG]     at Array.forEach (native)
[DEBUG]     at Function._.each._.forEach (/Users/ceck/.appcelerator/install/5.2.2/package/node_modules/alloy/Alloy/lib/alloy/underscore.js:79:11)
[DEBUG]     at /Users/ceck/.appcelerator/install/5.2.2/package/node_modules/alloy/Alloy/commands/compile/index.js:395:6
[DEBUG]     at Array.forEach (native)
[DEBUG]     at Function._.each._.forEach (/Users/ceck/.appcelerator/install/5.2.2/package/node_modules/alloy/Alloy/lib/alloy/underscore.js:79:11)
[DEBUG]     at module.exports (/Users/ceck/.appcelerator/install/5.2.2/package/node_modules/alloy/Alloy/commands/compile/index.js:391:4)
[DEBUG]     at Object.<anonymous> (/Users/ceck/.appcelerator/install/5.2.2/package/node_modules/alloy/Alloy/alloy.js:113:46)
[DEBUG]     at Module._compile (module.js:460:26)
[DEBUG]     at Object.Module._extensions..js (module.js:478:10)
[DEBUG]     at Module.load (module.js:355:32)
[DEBUG]     at Function.Module._load (module.js:310:12)
[DEBUG]     at Module.require (module.js:365:17)
[DEBUG]     at require (module.js:384:17)
[DEBUG]     at Object.<anonymous> (/Users/ceck/.appcelerator/install/5.2.2/package/node_modules/alloy/bin/alloy:3:1)
[DEBUG]     at Module._compile (module.js:460:26)
[DEBUG]     at Object.Module._extensions..js (module.js:478:10)
[DEBUG]     at Module.load (module.js:355:32)
[DEBUG]     at Function.Module._load (module.js:310:12)
[DEBUG]     at Function.Module.runMain (module.js:501:10)
[DEBUG]     at startup (node.js:129:16)
[DEBUG]     at node.js:814:3
[ERROR] Alloy compiler failed

0 个答案:

没有答案