javascript - Using a method inside a key value pair to truncate a string -
i using lodash , jquery library inside javascript , trying figure out how call method allow me truncate results of key value pair used create list inside .html code. html looks follows:
<div class="slide-in-panel"> <ul class="list-unstyled slide-in-menu-navigation" data-bind="foreach: __plugins"> <li class="btn-block"> <div class="btn btn-default btn-block" data-bind="click: $parent.showplugin, tooltip: 'shoebox.panel'"> <span data-bind="text: config.title"></span> <em class="webgis-icon webgis-cross slide-in-menu-remove-shoebox-button" data-bind="click: $parent.showremoveconfirmbox, tooltip: 'shoebox.removeshoebox'"> </em> </div> </li> </ul> </div> the key component data-bind="text: config.title" part. populates list name button. config.title created in javascript file below. goal apply method such .truncate() config.title part in javascript keep whatever name being populated, being long. how this?
return this.__backendshoeboxclient.createshoebox(this.__shoeboxname()).then((function(_this) { return function(shoebox) { return $when.join(shoebox.getname(), shoebox.getid(), shoebox.getusername()).then(function(arg) { var shoeboxid, shoeboxname, username; shoeboxname = arg[0], shoeboxid = arg[1], username = arg[2]; return _this.__shoeboxcontentfactory.create({ shoeboxid: shoeboxid, shoeboxname: shoeboxname, username: username }).then(function(arg1) { var activeshoeboxhandle, config, shoeboxcontent; shoeboxcontent = arg1.shoeboxcontent, activeshoeboxhandle = arg1.activeshoeboxhandle; _this.__activeshoeboxhandlemain.loadmodel(activeshoeboxhandle); config = { plugin: shoeboxcontent, title: shoeboxname, username: username, id: shoeboxid, handle: activeshoeboxhandle, icon: "" }; _this.add(config, null, null); activeshoeboxhandle.loadmodel(shoebox); _this.__shoeboxname.usedefaultvalue(); return _this.__shoeboxname.clearerror(); }); })["catch"](function(error) { __logger__.error("error while calling request " + error); return $when.reject(new error("error while calling request. " + error)); }); }; })(this)); }; i trying use knockout style binding this, without success:
<span data-bind="style: { textoverflow: ellipsis }, text: config.title"></span>
this should it: use truncate function this: config.title = _.truncate(config.title, {'length': maxlength});
return this.__backendshoeboxclient.createshoebox(this.__shoeboxname()).then((function(_this) { return function(shoebox) { return $when.join(shoebox.getname(), shoebox.getid(), shoebox.getusername()).then(function(arg) { var shoeboxid, shoeboxname, username; shoeboxname = arg[0], shoeboxid = arg[1], username = arg[2]; return _this.__shoeboxcontentfactory.create({ shoeboxid: shoeboxid, shoeboxname: shoeboxname, username: username }).then(function(arg1) { var activeshoeboxhandle, config, shoeboxcontent; shoeboxcontent = arg1.shoeboxcontent, activeshoeboxhandle = arg1.activeshoeboxhandle; _this.__activeshoeboxhandlemain.loadmodel(activeshoeboxhandle); config = { plugin: shoeboxcontent, title: shoeboxname, username: username, id: shoeboxid, handle: activeshoeboxhandle, icon: "" }; config.title = _.truncate(config.title, {'length': 15}); _this.add(config, null, null); activeshoeboxhandle.loadmodel(shoebox); _this.__shoeboxname.usedefaultvalue(); return _this.__shoeboxname.clearerror(); }); })["catch"](function(error) { __logger__.error("error while calling request " + error); return $when.reject(new error("error while calling request. " + error)); }); }; })(this)); };
Comments
Post a Comment