odoo12 widget的用法
-
var registry = require('web.field_registry'); 然后对应注册添加: // Basic fields registry .add('abstract', AbstractField) .add('input', basic_fields.InputField) .add('integer', basic_fields.FieldInteger) .add('boolean', basic_fields.FieldBoolean) .add('date', basic_fields.FieldDate) .add('datetime', basic_fields.FieldDateTime) .add('domain', basic_fields.FieldDomain) .add('text', basic_fields.FieldText) .add('html', basic_fields.FieldText) .add('float', basic_fields.FieldFloat) .add('char', basic_fields.FieldChar) .add('link_button', basic_fields.LinkButton) .add('handle', basic_fields.HandleWidget) .add('email', basic_fields.FieldEmail) .add('phone', basic_fields.FieldPhone) .add('url', basic_fields.UrlWidget) .add('CopyClipboardText', basic_fields.TextCopyClipboard) .add('CopyClipboardChar', basic_fields.CharCopyClipboard) .add('image', basic_fields.FieldBinaryImage) .add('binary', basic_fields.FieldBinaryFile) .add('pdf_viewer', basic_fields.FieldPdfViewer) .add('monetary', basic_fields.FieldMonetary) .add('percentage', basic_fields.FieldPercentage) .add('priority', basic_fields.PriorityWidget) .add('attachment_image', basic_fields.AttachmentImage) .add('label_selection', basic_fields.LabelSelection) .add('state_selection', basic_fields.StateSelectionWidget) .add('kanban_state_selection', basic_fields.StateSelectionWidget) .add('boolean_favorite', basic_fields.FavoriteWidget) .add('boolean_button', basic_fields.FieldBooleanButton) .add('boolean_toggle', basic_fields.BooleanToggle) .add('statinfo', basic_fields.StatInfo) .add('percentpie', basic_fields.FieldPercentPie) .add('float_time', basic_fields.FieldFloatTime) .add('float_factor', basic_fields.FieldFloatFactor) .add('float_toggle', basic_fields.FieldFloatToggle) .add('progressbar', basic_fields.FieldProgressBar) .add('toggle_button', basic_fields.FieldToggleBoolean) .add('dashboard_graph', basic_fields.JournalDashboardGraph) .add('ace', basic_fields.AceEditor);
-
注册之后, field的name属性消失了
odoo.define("account.upload_test", function(require){ "use strict" require('web.dom_ready'); var field_registry = require('web.field_registry'); var basic_field = require('web.basic_fields'); var Field_Text = basic_field.FieldText; var Imgs = Field_Text.extend({ start : function(){ var info = JSON.parse(this.value); console.log(info); }, }); field_registry.add('test_text', Imgs); return Imgs; });
view code
<field name="x_product_video" class="test_test" id="imageList" widget="test_text"/>
加载之后的页面, name属性没有了, JS中的代码可以正常执行, 请问是哪一步有问题
加载后渲染的代码
<span class="o_field_text o_field_empty test_test" data-original-title="" title=""></span>
-
@鲍永道
谢谢, 按照您的方法我已经成功处理了错误代码。
但当我在start方法里尝试用JQ.html() 方法向一个div中插入元素时并没有成功,尝试获取这个div也是空的start : function(){ var videos = this.record.data.x_product_video; var arr = videos.split(";"); var html = ""; for(var i = 0; i < arr.length; i++){ //add html html += ""; } $("#preview").html(html); console.log(document.getElementById("preview")); return this._super(); },