推送对象时,Knockout observableArray对象为空

时间:2017-10-25 08:59:03

标签: knockout.js

我有一个像这样结构的ViewModel:

function CallLogViewModel() {
        var self = this;

        // Observables
        self.client = {
            Id: ko.observable(),
            Name: ko.observable().extend({required: true, message: 'Name is required'}),
            Surname: ko.observable().extend({ required: true, message: 'Surname is required' }),
            EmailAddress: ko.observable().extend({ required: true, message: 'Email is required', email: true }),
            Mobile: ko.observable(),
            Fax: ko.observable(),
            Tel: ko.observable(),
            Area: ko.observable(),
            HasCar: ko.observable(),
            HeardAboutMethodId: ko.observable().extend({ required: true, message: 'Please select option' }),
            DateOfBirth: ko.observable().extend({ required: true, message: 'DateOfBirth is required' }),
            Comments: ko.observableArray(),
            Calls: ko.observableArray()
        };


        self.comment = {
            Id: ko.observable(),
            Value: ko.observable().extend({ required: true, message: 'Comment is required' }),
            ClientId: ko.observable(),
            Created: ko.observable()
        };


        self.addComment = function () {
            self.comment.Created = moment().format('YYYY-MM-DD, HH:mm:ss');
            self.client.Comments.push(self.comment);

            self.comment.Created = '';
            self.comment.Value = '';

            $('#ClientCommentsTable').DataTable();

            console.log(self.client.Comments());
        };


    };

当我将新的 self.comment 对象添加到数组对象中时,它会在表中显示注释,但数组对象显示值是空字符串吗?

是否与我如何清除评论对象有关?

1 个答案:

答案 0 :(得分:1)

试试这个:

if (activity.Type == ActivityTypes.Message)
{
    try
    {
        if (activity.Attachments.Count > 0)
        {
            var replyNoAttachmentAllowed = activity.CreateReply("This QnA bot cannot handle attachments, please send only text");
            await context.PostAsync(replyNoAttachmentAllowed);
        }
        else
        {
            // Check in QnA Dialog
            await Conversation.SendAsync(activity, () => new QnADialog());
        }
    }
    catch (Exception ex)
    {

        throw;
    }

}