Oracle JET:淘汰赛未更新变量 [英] Oracle JET: Knockout not updating variable

查看:94
本文介绍了Oracle JET:淘汰赛未更新变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下甲骨文喷射器和敲除html文件

I have the following oracle jet and knockout html file

<oj-dialog style="display:none;width: 600px;" id="addNewTag" title='Tag New Build' cancel-behavior='icon'>
        <div slot="body">
            <div class="oj-form-layout">
                <div class="oj-form oj-sm-odd-cols-12 oj-md-odd-cols-4 oj-md-labels-inline oj-form-cols-labels-inline oj-form-cols-max2">
                    <div class="oj-flex">
                        <div class="oj-flex-item">
                            <oj-label for="releaseVersion">Release Version</oj-label>
                        </div>  
                        <div class="oj-flex-item">
                            <oj-input-text id="releaseVersion" data-bind="attr: {value: jobDetails().faReleaseVersion}"></oj-input-text>
                        </div>  

我有以下JS文件的片段

I have following snippet of JS file

       self.addTagsToBuild = function (data) {
            self.jobDetails(data);
                $('#addNewTag').ojDialog('open');}

所以基本上我在点击按钮时调用了addTagsToBuild函数,这应该会打开一个对话框,并且我希望输入文本框的初始值是我在data-bind属性中声明的jobDetails().faReleaseVersion.不幸的是,当我正在运行此代码jobDetails()作为null传递,因此id = releaseVersion的输入文本的初始值为null.可能是什么问题?有指针吗?

So basically I am calling function addTagsToBuild on click of a button which should open a dialog box and I want initial value of input text box to be jobDetails().faReleaseVersion which I have declared in data-bind attribute.Unfotunately when I am running this code jobDetails() is being passed as null and so the initial value of input text with id=releaseVersion is null.What could be the issue? Any pointers?

推荐答案

oj-input-text(显然)是一个输入字段,因此它既可读写也可绑定到可观察对象.

oj-input-text is (obviously) an input field and so it both reads and writes to an observable you bind it to.

但是您的代码未将其绑定到可观察的对象.实际上,您甚至不应该将data-bind用于OJET组件,因为它们已在内部使用.您必须使用每个组件的自定义属性.

But your code is not binding it to an observable. In fact, you shouldn't even use data-bind for OJET components, because they are already used internally. You have to use the custom properties of each component.

首先,您需要为oj-input-text创建一个单独的可观察对象.为什么?因为如果不能观察到,则不会向HTML触发任何更改事件,以指示faReleaseVersion的值已被更新.

First, you need to create a separate observable for oj-input-text. Why? Because if it is not on observable then no change event will be fired to the HTML to indicate that the value of faReleaseVersion has been updated.

self.faReleaseVersion = ko.observable();
self.addTagsToBuild = function (data) {
        self.jobDetails(data);
        self.faReleaseVersion(data.faReleaseVersion);
        $('#addNewTag').ojDialog('open');}

接下来,使用oj-input-textvalue属性将其绑定到faReleaseVersion.

Next, use the value property of oj-input-text to bind it to faReleaseVersion.

<oj-input-text id="releaseVersion" value="{{faReleaseVersion}}"></oj-input-text>


这是 Cookbook 链接,显示了如何使用oj-input-text,这是文档.


Here's the Cookbook link that shows how to use oj-input-text, and here's the documentation.

这篇关于Oracle JET:淘汰赛未更新变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆