我已经搜索了答案,但是没有一个可以解决我的问题
我是nativescript的新手。我只是按照电子书的每个步骤进行操作。
电子书中的代码工作正常,但我的代码不行
这是代码(或电子书第158,159页或pdf第178,179页) 电子书:https://www.nativescript.org/get-the-nativescript-book
scrapbook.js
var observable = require("data/observable");
exports.onLoaded = function(args) {
var page = args.object;
var scrapbook = new observable.fromObject({
genders: ["Female", "Male", "Other"] });
page.bindingContext = scrapbook;
};
exports.onTap = function(args) {
var page = args.object;
var scrapbook = page.bindingContext;
console.log("You have made " + scrapbook.title);
console.log("Age: " + scrapbook.date.toLocaleDateString());
console.log("Gender selected:" + scrapbook.genders[scrapbook.gender]);
scrapbook.xml
<Page loaded="onLoaded">
<StackLayout>
<Label text="Title: " />
<TextField class="header" text="{{title}}" />
<Label text="Age: " />
<DatePicker date="{{ date }}" />
<Label text="Gender: " />
<ListPicker items="{{ genders }}" selectedIndex="{{gender }}" />
<Button tap="onTap" text="Done" />
</StackLayout>
TypeError:无法读取未定义的属性'toLocaleDateString'
如果我删除“ toLocaleDateString”
它打印:
设备Galaxy C5的日志:您未定义
设备Galaxy C5的日志:年龄:未定义
设备Galaxy C5的日志:未选择性别:未定义